User Macro Indiscriminately Removes some HTML Tags from Output
Asked by William Yeack:

In my instance of Confluence, I have a simple user macro that wraps whatever is inserted into it in a div. When I put a title and a paragraph into the content of the macro, the title is completely removed and the paragraph is stripped. However, if I include a second paragraph, then all of the content is rendered correctly.

Here is the macro:

    ## Macro title: DIV## Macro has a body: Y## Body processing: Rendered## Output: HTML## @param Class:title=Class|type=string|required=false|option-showNameInPlaceholder=false|option-showValueInPlaceholder=true## @param Style:title=Style|type=string|required=false|option-showNameInPlaceholder=false|option-showValueInPlaceholder=true<div class="$paramClass" style="$paramStyle">$body</div>

Here is the content that I am putting into the macro:

![1.png](/t5/image/serverpage/image-id/99401iCA99CAB5F8C0F6C0/image-size/large?v=v2&px=999 "1.png")

However, when the page is saved, the output removes the title and flattens the paragraph, leaving this:

![2.png](/t5/image/serverpage/image-id/99402i71D36D3C6D0D481D/image-size/large?v=v2&px=999 "2.png")

In terms of HTML, this output looks like the following:

    <div class="conf-macro output-inline" style="" data-hasbody="true" data-macro-name="div">This is the content.</div>

When I add a second paragraph, then the title and both paragraphs are rendered correctly, making the HTML on the rendered page look like this:

    <div class="conf-macro output-inline" style="" data-hasbody="true" data-macro-name="div"><h2 id="Contracts-Title">Title</h2><p>This is the content.</p><p>Second paragraph.</p></div>

Here is the markup from the page's source for the macro:

    <ac:structured-macro ac:macro-id="1014f412-f46d-475c-8308-1ba339d8390b" ac:name="div" ac:schema-version="1">  <ac:parameter ac:name="atlassian-macro-output-type">BLOCK</ac:parameter>  <ac:rich-text-body>    <h2>Title</h2>    <p>Content</p>  </ac:rich-text-body></ac:structured-macro>

I have tried removing all plugins, scripts, and styles from my Space but the behavior is the same.

Why is this simple macro changing the HTML content of its body at all let alone indiscriminately removing tags?


Answers:
author: Davin Studer
body: There is a bug ticket for this in JAC. It is [CONFSERVER-24634](https://jira.atlassian.com/browse/CONFSERVER-24634). Feel free to vote on it and watch the ticket and hopefully it can get fixed.

comments: author: William Yeack
body: I scoured Google (and I thought Atlassian's public JIRA...but maybe not) and I couldn't find this - thank you for digging it up, I'm glad to know at least that I'm not crazy!


author: Davin Studer
body: Unfortunatley, it's a pretty old issue ... which does not bode well for getting fixed. But make sure to add your vote. If it gets enough votes hopefully it can get addressed.


author: Matt Doar
body: I thought I saw a workaround buried in the comments?


author: Davin Studer
body: Yeah, it looks like the workaround is to have a blank paragraph inside the body of the macro ... not very elegant. I even tried doing this but no dice.

```
#set($body = $!body + "<p> </p>")
```

Looks like the header is stripped out of $body before even getting to the user macro. I verified that with the code block below which returns -1 ... meaning there is no header element in the string. : (

```
$body.indexOf("<h1>")
```


author: Peter-Dave Sheehan
body: /me scratches his head

I did some similar testing and found the same thing. So it's consistent at least.

The one thing I found is that if you change the body to "unrendered" then the h2 tag is present.

So something happens in the rendering phase of loading the body.

Oh wow... spent some time in script runner ... totally able to replicate the exact behavior.  
Check this out:

![2020-06-24 23_14_04-Script Console - https___team.qad.com_plugins_servlet_scriptrunner_admin_console.png](https://community.atlassian.com/t5/image/serverpage/image-id/100428iABD015E3B66A25D4/image-dimensions/626x437?v=v2 "2020-06-24 23_14_04-Script Console - https___team.qad.com_plugins_servlet_scriptrunner_admin_console.png")

comments: author: William Yeack
body: Wow that's nuts that it even does it with ScriptRunner - that's what I would have done to circumvent the rendering process but I guess that's out -


author: Dominic Lagger
body: Hi [@William Yeack](/t5/user/viewprofilepage/user-id/518819)

I tried with your macro and tested a bit and have to say, I have the same error and I'm just as confused as you are.

I asked the other community leaders, whether they have a possible solution for you.

Regards, Dominic

comments: author: William Yeack
body: Thanks Dominic!


Tags: atl-adm