How to insert regular HTML comments into Confluence HTML?
Asked by Jan:

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??


Answers:
author: Nic Brough -Adaptavist-
body: Embed them in a code or noformat macro.


author: Andre Vergison
body: 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!

comments: author: Stephen Deutsch
body: 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!


author: Stephen Deutsch
body: 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.

comments: author: Andre Vergison
body: 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.


author: Jan
body: Yep.


author: Doug Swartz
body: Or, put the HTML comment inside an HTML macro


author: Davin Studer
body: Another option would be to get the [Content Formatting Macros](https://marketplace.atlassian.com/plugins/com.adaptavist.confluence.contentFormattingMacros) (free). You get a HTML Comment macro with it.


author: Stephen Deutsch
body: When you say HTML edit mode, do you mean using the Source Editor to look at the XHTML source?