all repos — grayfriday @ 133788657b0ddebf0e884571fc99a5528e55a10f

blackfriday fork with a few changes

Refix fenced code blocks w/o preceding blank lines

Change approach at fixing #45: don't patch input markdown at preprocess
pass, instead improve special case detection when parsing paragraphs.

Leave the fenced code block detection in the preprocess pass though,
it's been put to another use since then, to suppress tab expansion
inside code blocks.
Vytautas Ĺ altenis vytas@rtfb.lt
Wed, 28 Oct 2015 21:37:14 +0200
commit

133788657b0ddebf0e884571fc99a5528e55a10f

parent

d4ee3ea08bf2f1471dbf7846090d9dd931609968

2 files changed, 10 insertions(+), 6 deletions(-)

jump to
M block.goblock.go

@@ -1342,6 +1342,14 @@ p.renderParagraph(out, data[:i])

return i } + // if there's a fenced code block, paragraph is over + if p.flags&EXTENSION_FENCED_CODE != 0 { + if p.fencedCode(out, current, false) > 0 { + p.renderParagraph(out, data[:i]) + return i + } + } + // if there's a definition list item, prev line is a definition term if p.flags&EXTENSION_DEFINITION_LISTS != 0 { if p.dliPrefix(current) != 0 {
M markdown.gomarkdown.go

@@ -393,7 +393,6 @@ if p.flags&EXTENSION_TAB_SIZE_EIGHT != 0 {

tabSize = TAB_SIZE_EIGHT } beg, end := 0, 0 - lastLineWasBlank := false lastFencedCodeBlockEnd := 0 for beg < len(input) { // iterate over lines if end = isReference(p, input[beg:], tabSize); end > 0 {

@@ -405,16 +404,13 @@ end++

} if p.flags&EXTENSION_FENCED_CODE != 0 { - // when last line was none blank and a fenced code block comes after + // track fenced code block boundaries to suppress tab expansion + // inside them: if beg >= lastFencedCodeBlockEnd { if i := p.fencedCode(&out, input[beg:], false); i > 0 { - if !lastLineWasBlank { - out.WriteByte('\n') // need to inject additional linebreak - } lastFencedCodeBlockEnd = beg + i } } - lastLineWasBlank = end == beg } // add the line body if present