Merge pull request #60 from shurcooL/fix/fenced-code-block-extra-newline
Fix for potential extra newline added inside fenced code blocks.pull/64/head
commit
5bcdd5eb7f
|
@ -711,6 +711,12 @@ func TestFencedCodeBlock(t *testing.T) {
|
||||||
|
|
||||||
"`",
|
"`",
|
||||||
"<p>`</p>\n",
|
"<p>`</p>\n",
|
||||||
|
|
||||||
|
"Bla bla\n\n``` oz\ncode blocks breakup paragraphs\n```\n\nBla Bla\n\n``` oz\nmultiple code blocks work okay\n```\n\nBla Bla\n",
|
||||||
|
"<p>Bla bla</p>\n\n<pre><code class=\"oz\">code blocks breakup paragraphs\n</code></pre>\n\n<p>Bla Bla</p>\n\n<pre><code class=\"oz\">multiple code blocks work okay\n</code></pre>\n\n<p>Bla Bla</p>\n",
|
||||||
|
|
||||||
|
"Some text before a fenced code block\n``` oz\ncode blocks breakup paragraphs\n```\nSome text in between\n``` oz\nmultiple code blocks work okay\n```\nAnd some text after a fenced code block",
|
||||||
|
"<p>Some text before a fenced code block</p>\n\n<pre><code class=\"oz\">code blocks breakup paragraphs\n</code></pre>\n\n<p>Some text in between</p>\n\n<pre><code class=\"oz\">multiple code blocks work okay\n</code></pre>\n\n<p>And some text after a fenced code block</p>\n",
|
||||||
}
|
}
|
||||||
doTestsBlock(t, tests, EXTENSION_FENCED_CODE)
|
doTestsBlock(t, tests, EXTENSION_FENCED_CODE)
|
||||||
}
|
}
|
||||||
|
|
|
@ -330,9 +330,11 @@ func firstPass(p *parser, input []byte) []byte {
|
||||||
|
|
||||||
if p.flags&EXTENSION_FENCED_CODE != 0 {
|
if p.flags&EXTENSION_FENCED_CODE != 0 {
|
||||||
// when last line was none blank and a fenced code block comes after
|
// when last line was none blank and a fenced code block comes after
|
||||||
if !lastLineWasBlank && beg >= lastFencedCodeBlockEnd {
|
if beg >= lastFencedCodeBlockEnd {
|
||||||
if i := p.fencedCode(&out, append(input[beg:], '\n'), false); i > 0 {
|
if i := p.fencedCode(&out, append(input[beg:], '\n'), false); i > 0 {
|
||||||
out.WriteByte('\n') // need to inject additional linebreak
|
if !lastLineWasBlank {
|
||||||
|
out.WriteByte('\n') // need to inject additional linebreak
|
||||||
|
}
|
||||||
lastFencedCodeBlockEnd = beg + i
|
lastFencedCodeBlockEnd = beg + i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue