all repos — grayfriday @ cd3fa08cb15a5c07b87d967cea59653e63948a77

blackfriday fork with a few changes

fix issue #45: 'Fenced Code Blocks without a blank line before'

Add missing newline between paragraph and fenced code block within `firstPass()`.
Mathias Leppich mleppich@muhqu.de
Sun, 30 Mar 2014 21:57:58 +0200
commit

cd3fa08cb15a5c07b87d967cea59653e63948a77

parent

a4274bba514ae50505413a2c31fc25728054c9b0

2 files changed, 21 insertions(+), 4 deletions(-)

jump to
M block.goblock.go

@@ -101,7 +101,7 @@ // return n * fact(n-1)

// } // ``` if p.flags&EXTENSION_FENCED_CODE != 0 { - if i := p.fencedCode(out, data); i > 0 { + if i := p.fencedCode(out, data, true); i > 0 { data = data[i:] continue }

@@ -599,7 +599,7 @@ skip = i + 1

return } -func (p *parser) fencedCode(out *bytes.Buffer, data []byte) int { +func (p *parser) fencedCode(out *bytes.Buffer, data []byte, doRender bool) int { var lang *string beg, marker := p.isFencedCode(data, &lang, "") if beg == 0 || beg >= len(data) {

@@ -631,7 +631,9 @@ return 0

} // verbatim copy to the working buffer - work.Write(data[beg:end]) + if doRender { + work.Write(data[beg:end]) + } beg = end }

@@ -640,7 +642,9 @@ if lang != nil {

syntax = *lang } - p.r.BlockCode(out, work.Bytes(), syntax) + if doRender { + p.r.BlockCode(out, work.Bytes(), syntax) + } return beg }
M markdown.gomarkdown.go

@@ -305,6 +305,7 @@ // - extract references

// - expand tabs // - normalize newlines // - copy everything else +// - add missing newlines before fenced code blocks func firstPass(p *parser, input []byte) []byte { var out bytes.Buffer tabSize := TAB_SIZE_DEFAULT

@@ -312,6 +313,8 @@ 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 { beg += end

@@ -320,6 +323,16 @@ end = beg

for end < len(input) && input[end] != '\n' && input[end] != '\r' { end++ } + + // when last line was none blank and a fenced code block comes after + if !lastLineWasBlank && beg >= lastFencedCodeBlockEnd { + i := p.fencedCode(&out, append(input[beg:], '\n'), false) + if i > 0 { + out.WriteByte('\n') // need to inject additional linebreak + lastFencedCodeBlockEnd = beg + i + } + } + lastLineWasBlank = end == beg // add the line body if present if end > beg {