How to insert regular HTML comments into Confluence HTML?

If I switch to HTML edit mode in confluence and write simple plain old HTML comments.. <!-- test 123 --> they get killed by confluence. This sucks!! 

 

Is there a way to tell confluence to leave my HTML untouched??

7 answers

This widget could not be displayed.

Embed them in a code or noformat macro.

This widget could not be displayed.
Stephen Deutsch Community Champion Sep 18, 2015

When you say HTML edit mode, do you mean using the Source Editor to look at the XHTML source?

This widget could not be displayed.
Davin Studer Community Champion Sep 18, 2015

Another option would be to get the Content Formatting Macros (free). You get a HTML Comment macro with it.

This widget could not be displayed.

Or, put the HTML comment inside an HTML macro

This widget could not be displayed.

Yep.

This widget could not be displayed.
Stephen Deutsch Community Champion Sep 22, 2015

It seems like Confluence filters out HTML comments from the XHTML source when saving it.  One possibility is using div with a class of "hidden" (since Confluence doesn't filter out div tags) and insert your comment in that.  Then you will have a comment that doesn't show in the editor but will show in the source editor.

Unfortunately there's no way I know of to customize the XHTML parser to not remove plain HTML comments.

Div tags generate newlines.

I entered this text:

<p>Today will be a beautiful day</p>
<p>Today is a <div class="hidden">before</div>beautiful day<div class="hidden">after</div></p>
<p>Today was a beautiful day</p>

And here's the result:

Today will be a beautiful day

Today is a

beautiful day

Today was a beautiful day

<p>Today will be a beautiful day</p>
<p>Today is a</p>
<div class="hidden">before</div>
<p>beautiful day</p>
<div class="hidden">after</div>
<p>Today was a beautiful day</p>

:(

 

Take 2: Using the HTML comment macro:

Getting this:

Today will be a beautiful day

Today is abeautifulday

Today was a beautiful day

<p>Today will be a beautiful day</p>
<p>Today is a </p>
<ac:structured-macro ac:macro-id="4c1b09e8-6bc4-4ca4-a86c-c9e6969f146d" ac:name="htmlcomment" ac:schema-version="1">
<ac:parameter ac:name="atlassian-macro-output-type">INLINE</ac:parameter>
<ac:rich-text-body>
<p>before</p>
</ac:rich-text-body>
</ac:structured-macro>
<p> beautiful </p>
<ac:structured-macro ac:macro-id="ad3f6868-9c20-406f-89c8-e85db358c398" ac:name="htmlcomment" ac:schema-version="1">
<ac:parameter ac:name="hidden">true</ac:parameter>
<ac:parameter ac:name="atlassian-macro-output-type">INLINE</ac:parameter>
<ac:rich-text-body>
<p>after</p>
</ac:rich-text-body>
</ac:structured-macro>
<p> day</p>
<p>Today was a beautiful day</p>

Loosing spaces/ Okay, I add spaces in the xml:

<p>Today is a  </p>
<ac:struct...-macro>
<p>  beautiful  </p>
<ac:struct...-macro>
<p>  day</p>

Result:

Today will be a beautiful day

Today is abeautifulday

Today was a beautiful day

They strip off the leading and trailing text spaces.

:(  :(

So as a solution to replace html comments both div and macro are useless. And macro's add a lot of text bloat.

This widget could not be displayed.

My colleague Jack Chen at Quest suggested using span instead of div. And this works GREAT! :)

IOW you can put the string

<span class="hidden">some comment here</span>

about everywhere in the XML text, it will be decently saved and won't alter the page layout.

Thanks Jack!

Stephen Deutsch Community Champion May 16, 2017

Hmm... I feel like I remember span tags not working before, but maybe I was confused. Anyways, this would be the preferred method as it does not mess up the spacing. Glad to hear it worked!

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Monday in Confluence

Why start from scratch? Introducing four new templates for Confluence Cloud

Hi my Community friends!  For those who don't know me, I'm a product marketer on the Confluence Cloud team - nice to meet you! For those of you who do, you know that I've been all up in your Co...

293 views 2 4
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you