mirror of
https://github.com/russross/blackfriday.git
synced 2024-03-22 13:40:34 +08:00
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.
This commit is contained in:
parent
3a90da10e3
commit
36787eca3a
5
block.go
5
block.go
|
@ -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] == '\\' {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user