diff --git a/block.go b/block.go index 768c40b..a8e73d8 100644 --- a/block.go +++ b/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 { diff --git a/markdown.go b/markdown.go index 1e3fa93..76f4dc5 100644 --- a/markdown.go +++ b/markdown.go @@ -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