Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to insert regular HTML comments into Confluence HTML?

Jan September 18, 2015

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

1 vote
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 18, 2015

Embed them in a code or noformat macro.

0 votes
Andre Vergison May 16, 2017

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
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.
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!

0 votes
Stephen Deutsch
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.
September 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.

Andre Vergison May 13, 2017

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.

0 votes
Jan September 21, 2015

Yep.

0 votes
Doug Swartz
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.
September 21, 2015

Or, put the HTML comment inside an HTML macro

0 votes
Davin Studer
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.
September 18, 2015

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

0 votes
Stephen Deutsch
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.
September 18, 2015

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events