Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inline confluence user macro

How to create a confluence macro with body that produces an inline output? The following macro:

## @noparams
<font color="red">$body</font>

applied to this text

Before macro [macro starts here]macro body[macro ends here] after macro.

Will create this HTML code:

<p>Before macro </p>
<font color="red">macro body</font>
<p>after macro.</p>

How to remove the <p></p> tags?

like image 689
MrTJ Avatar asked Apr 24 '12 16:04

MrTJ


People also ask

What is user macro in Confluence?

User macros are useful if you want to create your own custom macros. These can be to perform specific actions, apply custom formatting and much more. User macros are created and managed within Confluence itself, you do not need to develop an app (plugin).

How do I add a status macro in Confluence?

To add the Status macro to a page:From the editor toolbar, choose Insert > Other Macros. Choose Status from the Confluence content category. Enter a status and choose a color. Choose Insert.

How do I create a line break in Confluence?

You can try using shift + return (enter for windows) to insert a line break.

What is excerpt macro in Confluence?

The Atlassian Community is here for you. Add the Excerpt macro to a page to define a snippet of content to be re-used on another page. This is great single sourcing important information. For example you could provide the contact details and dates from each project page on a summary page.


1 Answers

This is an issue with Confluence. To avoid this, you have to use html output. If the body or your macro contain wiki markup, then you will have to render this by hand. My workaround is as follows:

## Use this macro to avoid new lines:
#macro(doNothing)#end
##
## (Do stuff with body in wiki format, if appropriate)
##
## Convert to html and remove paragraph tags:
#set($renderedhtml = "")
#if ($body && ($body.length()>0))
  #set($globalHelper = $action.getHelper())
  #set($renderedhtml = $globalHelper.renderConfluenceMacro("$body").replaceAll("</?[pP]>",""))
#end
##
## (Do stuff with body in html format, if appropriate)
##
## Output text:
$renderedhtml#doNothing()

EDIT: You will want to modify the regex if there are p tags in your macro that you want to keep. The regex in the code above will remove ALL p tags.

like image 154
boileau Avatar answered Sep 30 '22 03:09

boileau