are macros now always wrapped in tags?

Christopher Martino July 29, 2013

I have the following macro code:

#if($param0) {report-block:injected=true} {content-reporter:key=content:children|matchAll=true|type=page|space=+SITE|scope=SITE:Terms > children} {text-filter:content:title|include=$param0} {content-reporter} {report-body}{html}<span style="border: 3px outset blue;" onmouseover="this.style.border='3px inset blue';" onmouseout="this.style.border='3px outset blue';"><a title="%data:definition%">%content:title%</a></span>{html}{report-body} {report-empty} $param0 {report-empty} {report-block} #else {color:red}Search term required, see this page for more info: [TOOL:Terms]{color} #end

The above code renders a blue 3D box around some text and displays it inline with the rest of the text around it. In Confluence 3.5 this worked perfectly.

However, I've recently upgraded to Confluence version 4.2 and my custom macro now pushes the text inside the blue box to a new line and creates a new line after it.

I am wondering if there is something new in Confluence version 4.2 that is causing this behavior (because I did not change the code of the macro).

Are macros in Confluence 4.2 now always wrapped in <p> tags? Is this because of the conversion to XHTML?

Any information is greatly appreciated! Thanks!

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
Answer accepted
Matthew J. Horn
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 31, 2013

I've done something like this, by creating a macro that calls a macro. This should give you an idea:

#set($xhtml=$globalHelper.renderConfluenceMacro(somemacro))

## remove leading &lt;p&gt; and trailing &lt;/p&gt;
#if($xhtml.startsWith("&lt;p&gt;",0) &amp;&amp; $xhtml.endsWith("&lt;/p&gt;"))
  #set($len=$xhtml.length()-$generalUtil.convertToInteger(4))
  #set($xhtml=$xhtml.substring(3,$len))
#end
${xhtml}

Christopher Martino July 31, 2013

Hello Matthew,

Thank you for this post! I have created the user macro as you have defined above and called it removeptags. How to I pass in a macro to the macro you posted above?

Like this?

#set($xhtml=$globalHelper.renderConfluenceMacro({mymacroname}))

Or, should I edit the content of the desired page and add this...

{removeptags}{mymacroname}{removeptags}

Chris

Matthew J. Horn
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 1, 2013
Christopher Martino August 6, 2013

This is still not working for me. Let me explain what I am trying to do... I have this macro called 'term' which used to work in version 3.5:

{code}

#if($param0) {report-block:injected=true} {content-reporter:key=content:children|matchAll=true|type=page|space=+SITE|scope=SITE:Terms > children} {text-filter:content:title|include=$param0} {content-reporter} {report-body}{html}<span style="border: 3px outset blue;" onmouseover="this.style.border='3px inset blue';" onmouseout="this.style.border='3px outset blue';"><a title="%data:definition%">%content:title%</a></span>{html}{report-body} {report-empty} $param0 {report-empty} {report-block} #else {color:red}Search term required, see this page for more info: [TOOL:Terms]{color} #end

{code}

The above macro takes in a parameter which is the text that will be surrounded by a blue box. Also, the Output Format for this macro used to be 'Wiki Markup', but now it is set to 'HTML' and I do not have the Output Format drop down box to change it back to 'Wiki Markup' (how can I do that?). This no longer works in version 4.2 because <p> tags are placed around the output (hence the reason for my question). So, with your suggestion, I have created a macro called 'removeptags' that looks like this:

{code}

#set($xhtml=$globalHelper.renderConfluenceMacro({term}))

## remove leading <p> and trailing </p>
#if($xhtml.startsWith("<p>",0) && $xhtml.endsWith("</p>"))
#set($len=$xhtml.length()-$generalUtil.convertToInteger(4))
#set($xhtml=$xhtml.substring(3,$len))
#end
${xhtml}

{code}

To add these macros to a page, I edit the page, choose to insert wiki markup, and type the following inside the wiki markup box:

{code}

{removeptags}

{term|wiki}

{removeptags}

{code}

But, I get a red error message on the page that says "Error rendering macro 'removeptags' : Error occurred rendering template content". How can I pass the 'term' macro WITH a parameter to the 'removeptags' macro so that I can get the blue box to render around text and also have the <p> tags removed?

Matthew J. Horn
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 6, 2013

You can pass parameters to a macro you call within a macro using the following syntax:

$helper.renderConfluenceMacro("{macro_name:param_name=param_value}")

Separate multiple parameters with a pipe. For example:

$helper.renderConfluenceMacro("{pagetree: root=@home | sort=position | searchBox=false | startDepth=1 }")

hth,

matt

Christopher Martino August 13, 2013

Hi Matthew,

I've modified my removeptags macro as follows:

#set($xhtml=$globalHelper.renderConfluenceMacro("{term:$param0}"))
## remove leading &lt;p&gt; and trailing &lt;/p&gt;
#if($xhtml.startsWith("&lt;p&gt;",0) &amp;&amp; $xhtml.endsWith("&lt;/p&gt;"))
  #set($len=$xhtml.length()-$generalUtil.convertToInteger(4))
  #set($xhtml=$xhtml.substring(3,$len))
#end
${xhtml}

I call the term macro as follows:

{term|wiki}

However, the page only displays the text:

${xhtml}

What am I doing wrong?

Chris

Matthew J. Horn
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 13, 2013

Alright, let's back up. Can you provide the full bodies and settings on the macros that you're creating?

Christopher Martino August 20, 2013

Hello Matt,

Sorry for the late reply. I've been on vacation for the past week.

The first macro I have is the removeptags macro. Here are the details:

Macro Body Processing: Rendered

Template:

#set($xhtml=$globalHelper.renderConfluenceMacro("{term:$param0}"))
 
## remove leading &lt;p&gt; and trailing &lt;/p&gt;
#if($xhtml.startsWith("&lt;p&gt;",0) &amp;&amp; $xhtml.endsWith("&lt;/p&gt;"))
  #set($len=$xhtml.length()-$generalUtil.convertToInteger(4))
  #set($xhtml=$xhtml.substring(3,$len))
#end
${xhtml}

The second macro I have is the term macro. Here are the details:

Macro Body Processing: No Macro Body

Template:

#if($param0)
{report-block:injected=true}
{content-reporter:key=content:children|matchAll=true|type=page|space=+SITE|scope=SITE:Terms &gt; children}
{text-filter:content:title|include=$param0}
{content-reporter}
{report-body}
{html}
&lt;span style="border: 3px outset blue" onmouseover="this.style.border='3px inset blue'" onmouseout="this.style.border='3px outset blue'"&gt;&lt;a title="%data:definition%"&gt;%content:title%&lt;/a&gt;&lt;/span&gt;
{html}
{report-body}
{report-empty} $param0 {report-empty}
{report-block}
#else
{color:red}Search term required, see this page for more info: [TOOL:Terms]{color}
#end

When I use the term macro on a page, I pass in a parameter. Here are the steps I take:

1. Edit the page

2. Click on Insert->Wiki Markup

3. Then I enter the following code and click on the Insert button:

{removeptags}

4. Inside the removeptags macro, I repeat steps 2 and 3 with the following code:

{term|wiki}

5. Save the page

The only text that renders is "${xhtml}" and I dont really understand why. =/

Do you know what I'm doing wrong?

Chris

Christopher Martino August 25, 2013

Hello Matt,

I'm just wondering if you have had time to look over my comment above. Please let me know your thoughts. Thanks!

Chris

Matthew J. Horn
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 25, 2013

Sorry it's been a bit crazy at work the last week or so. Can you email privately and remind me... would be later in the week that I can try this out. My email addy is the first letter of my first name, my last name, at verivo.com.

Christopher Martino August 25, 2013

Hi Matt,

No problem at all! It's been very busy for me as well.

I sent you an email at the address you provided. Please let me know your thoughts whenever you get the chance. Thanks!

Chris

1 vote
TtheB
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 31, 2013

I can confirm, that I also discovered this behavior in Confluence 4.3.7 and created a bug report:

https://jira.atlassian.com/browse/CONF-28369

From the bug report, it seems that the error is fixed in Confluence 5.1. Which also means, that there will be no fix for Confluence 4.3.7.

Christopher Martino July 31, 2013

Thank you for the info TtheB! I assume you did not find any work around in Confluence 4.3.7 to eliminate the <p> tags?

TtheB
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 1, 2013

No, I just tweaked my custom stylesheet to compensate the effect.

0 votes
Guilherme Nedel [Atlassian]
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 31, 2013

Hi Chris, also, the user macros should be adapted in order to function with the new XHTML markup from Confluence 4 on. For detailed information on the changes, please refer to this page with instructions.

There are also presentation slides from Confluence 4 changes if you have interest.

Finally there is a good thread here about the same topic.

Christopher Martino July 31, 2013

Thanks for the post Guilherme! I looked through the links that you provided, but I could not find any information on how to remove the unwanted <p> tags. Do you know how to do that?

Guilherme Nedel [Atlassian]
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 1, 2013

I guess Matthew has a good solution for that. :)

Please mind to mark the best answers as accepted (the check mark icon on the top right) once you have fullfilled your query, that can help other Answers users to find relevant content!

Cheers

TAGS
AUG Leaders

Atlassian Community Events