What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 134 Stack Exchange communities.

While fixing up a broken imgur link on StackApps, I noticed that a HTML comment in a post that contains a URL that Markdown might parse will break in the preview if that comment is followed by at least one more HTML comment. It also breaks in the rendered post if that comment is followed by at least two more HTML comments, as is the case in the screenshot below.

In less confusing terms, this happens:

Example of HTML comments gone wrong on StackApps

Live example:

<!-- http://s -->
<!-- -->
<!-- -->

gives us

This may be related to a recent change to address this issue, since this worked fine before.

share|improve this question
1  
Workaround until this is fixed: put a blank line in between comments –  balpha Jun 22 '11 at 6:22

1 Answer 1

up vote 3 down vote accepted

This wasn't even really a new bug – this was always broken:

You may be right <!-- http://xkcd.com/386 --> about this.

turned into

You may be right http://xkcd.com/386 --> about this.

because the auto-linker did this:

You may be right <!-- <a href="http://xkcd.com/386">http://xkcd.com/386</a> --> about this.

and the tag sanitizer eats anything starting with a < until the next > (or end of text) that is not whitelisted – and the "tag"

<!-- <a href="http://xkcd.com/386">

certainly isn't.

This just didn't come up before, because until the recent change to HTML comments, the StackApps triad (where you noticed this) was incorrectly considered to be a block-level comment.

Yeah, you heard that right. Markdown distinguishes between block-level HTML comments and inline HTML comments :\

And since block-level elements do not get any treatment per the Markdown "spec" (which, by the way, doesn't mention HTML comments at all; I'm just deducing this from the actual code, which does handle them), the auto-linker just wasn't run over these comments previously.

Putting blank lines between the comments turns them into block-level, hence the workaround from my comment on your question.

It's fixed now, so after the next build, this will work either way (by not running the auto-linker within comments).

The inconsistency between the preview and final not yet fixed, but it is very minor and should not be a real-world problem (the only difference being the insertion of an empty <p></p>).

share|improve this answer
    
Ahh, that makes sense. Well, as much sense as distinguishing between block-level and inline HTML comments can make I suppose. Good stuff! –  Tim Stone Jun 22 '11 at 9:39

You must log in to answer this question.

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