Allow heading to end with \#

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 #146.
pull/161/head
Vytautas Šaltenis 2015-04-07 21:12:29 +03:00
parent 3a90da10e3
commit 36787eca3a
2 changed files with 13 additions and 1 deletions

View File

@ -221,6 +221,9 @@ func (p *parser) prefixHeader(out *bytes.Buffer, data []byte) int {
}
}
for end > 0 && data[end-1] == '#' {
if isBackslashEscaped(data, end-1) {
break
}
end--
}
for end > 0 && data[end-1] == ' ' {
@ -733,7 +736,7 @@ func (p *parser) table(out *bytes.Buffer, data []byte) int {
return i
}
// check if the specified position is preceeded by an odd number of backslashes
// check if the specified position is preceded by an odd number of backslashes
func isBackslashEscaped(data []byte, i int) bool {
backslashes := 0
for i-backslashes-1 >= 0 && data[i-backslashes-1] == '\\' {

View File

@ -132,6 +132,15 @@ func TestPrefixHeaderNoExtensions(t *testing.T) {
"* List\n * Nested list\n # Nested header\n",
"<ul>\n<li><p>List</p>\n\n<ul>\n<li><p>Nested list</p>\n\n" +
"<h1>Nested header</h1></li>\n</ul></li>\n</ul>\n",
"#Header 1 \\#\n",
"<h1>Header 1 #</h1>\n",
"#Header 1 \\# foo\n",
"<h1>Header 1 # foo</h1>\n",
"#Header 1 #\\##\n",
"<h1>Header 1 ##</h1>\n",
}
doTestsBlock(t, tests, 0)
}