Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escaped # not rendered in headings when it's last character #146

Closed
anthonyfok opened this issue Feb 10, 2015 · 1 comment
Closed

Escaped # not rendered in headings when it's last character #146

anthonyfok opened this issue Feb 10, 2015 · 1 comment

Comments

@anthonyfok
Copy link
Contributor

@hagbarddenstore has kindly reported "Escaped # not rendered in headings when it's last character" at gohugoio/hugo#879 as a Hugo issue, though it belongs to the realm of Blackfriday. I have reproduced @hagbarddenstore's report verbatim below:


Example Markdown:

# Broken heading \#

This produces the following HTML:

<h1>Broken heading</h1>

But if I add something after the escaped # it will be rendered.

# Working heading \# with escaped signs...

And this renders the following HTML:

<h1>Working heading # with escaped signs...</h1>

Escaping the # sign works everywhere else, but not as the last character.

The bug can be avoided by simply appending a space as the last character, but that's kind of icky.

@anthonyfok
Copy link
Contributor Author

For a wider perspective, it appears that various Markdown engines exhibit different behaviours in your test case:

John Gruber's original Markdown.pl and GitHub Flavored Markdown (GFM)

# Broken heading \# gives <h1>Broken heading \</h1>, hence

Broken heading \

Kramdown

# Broken heading \# gives <h1 id="broken-heading-">Broken heading #</h1>, i.e.

Broken heading #

which matches your desired output.


I haven't tested the other Markdown engines yet. It seems that out of the three, only Kramdown got it right?

Note that http://daringfireball.net/projects/markdown/syntax#backslash does mention that the backslash may be used to escape the # hash mark character.

Nevertheless, I think it may be a good idea for Blackfriday to follow one of the behaviours above. 😉

rtfb added a commit to rtfb/blackfriday that referenced this issue Apr 7, 2015
The problem was in a loop that skipped the optional closing hashes in a
heading like this:

    ### This is an H3 ###

Now it checks to see if a hash is escaped and if it is, treats it as a
rightmost character of the heading text, like this:

    ### This is an H3 #\##   ==>   ### This is an H3 ##

Fixes issue russross#146.
@rtfb rtfb mentioned this issue Apr 7, 2015
@rtfb rtfb closed this as completed May 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants