vmg / redcarpet

The safe Markdown parser, reloaded.
MIT License
4.99k stars 527 forks source link

Escaped pound signs are not rendered in headers that open with pound #447

Open vincentwoo opened 9 years ago

vincentwoo commented 9 years ago
>> markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, tables: true)

>> markdown.render("\\#")
"<p>#</p>\n"
>> markdown.render("#\\#")
"<h1>\\</h1>\n"
>> markdown.render("\\#\n---")
"<h2>#</h2>\n"

In the first example, redcarpet properly turns \# into a #, but #\#, a header which should have just a pound sign as its contents, turns into a header with just a slash in it. Using the newline-with-dashes to denote a header seems to work, though.

davidalpert commented 9 years ago

I've just run into this also. Wanted to use C# in a header but all I get is C or C\

davidalpert commented 9 years ago

Although on a hunch, after looking at Daring Fireball's spec for header syntax, I tried adding a trailing space to my heading and got the # sign to render.

In otherwords:

## Now Consider C#

didn't render the trailing # but

## Now Consider C#_

(if you replace that underscore with a trailing space) the # rendered fine.