all repos — grayfriday @ 36787eca3aa824e3c17b9c00feaf307c543fbe97

blackfriday fork with a few changes

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.
Vytautas Ĺ altenis vytas@rtfb.lt
Tue, 07 Apr 2015 21:12:29 +0300
commit

36787eca3aa824e3c17b9c00feaf307c543fbe97

parent

3a90da10e373e33f9d809d0324741aade90b7299

2 files changed, 13 insertions(+), 1 deletions(-)

jump to
M block.goblock.go

@@ -221,6 +221,9 @@ }

} } for end > 0 && data[end-1] == '#' { + if isBackslashEscaped(data, end-1) { + break + } end-- } for end > 0 && data[end-1] == ' ' {

@@ -733,7 +736,7 @@

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] == '\\' {
M block_test.goblock_test.go

@@ -132,6 +132,15 @@

"* 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) }