mirror of
https://github.com/russross/blackfriday.git
synced 2024-03-22 13:40:34 +08:00
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.
This commit is contained in:
parent
d4ee3ea08b
commit
133788657b
8
block.go
8
block.go
|
@ -1342,6 +1342,14 @@ func (p *parser) paragraph(out *bytes.Buffer, data []byte) int {
|
|||
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 {
|
||||
|
|
|
@ -393,7 +393,6 @@ func firstPass(p *parser, input []byte) []byte {
|
|||
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 @@ func firstPass(p *parser, input []byte) []byte {
|
|||
}
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue
Block a user