Ok, a while ago (a few seconds after I joined SE Network first time), I saw a thing which I found particularly interesting. If I want, I can hide a comment inside a post just by placing a < in front of it on a newline. For example, below is something hidden as of now, but you won't be able to see it:

But, If you click the edit button below, and see the markdown, its here!

So, is it an intentional feature?

Is it against the dense SE laws to hide such comments inside posts?

  • 3
    There's even real syntax for comments <!-- comment --> which is useful in some corner cases (and for code highlighting). – Mat May 20 '14 at 11:11
  • 1
    Why would you want to? But sure, you can if you want. – Oded May 20 '14 at 11:11
  • @Mat Ok, I didn't know that, thanks for pointing that out... Cheers! – user3459110 May 20 '14 at 11:12
  • 1
    @Oded For the same reason geeky programmers keep whispering to themselves, or blogging on a private blog, while locked behind a screen filled of random characters, trying to solve a coding horror... – user3459110 May 20 '14 at 11:13

Sure, that's fine. It's rare, but sometimes this is actually helpful; for an example see the Markdown source of this answer.

The fact that this behaves like a comment is really just a side effect, because the HTML sanitizer will grab anything that starts with a < and ends with the next >, and if it doesn't match a white list, it will just remove it.

Even HTML comments (like <!-- foo -->), while being handled by the Markdown phase, will simply disappear during the sanitization phase because they're not whitelisted.

However, even though a single < would (mostly) behave the same way, you should use "real" HTML comments because

  • it's clearer, and
  • there's still some special handling of HTML comments in the Markdown processor.
  • Ohh, thats really great link... Btw, why not then remove the way I stated and just keep the one you mentioned? Its better in my view... – user3459110 May 20 '14 at 11:24
  • 2
    @AwalGarg Again, it's merely a side-effect -- you're creating invalid HTML, and we remove it. Not doing that isn't really an option. – balpha May 20 '14 at 11:26
  • Ok, thnx. Ahh yes, I know the html thing of course... I just thought, maybe SE guys have some superhuman way of sanitization... – user3459110 May 20 '14 at 11:28
  • 1
    Nope, it's very very simple. See here, lines 18 through 35 -- that's all. – balpha May 20 '14 at 11:36
  • @balpha: What would be an option would be to HTML-escape the non-whitelisted tags (turning e.g. <foobar> into &lt;foobar&gt;) instead of just stripping them, so that they'd get displayed as plain text. – Ilmari Karonen May 20 '14 at 17:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .