Merge pull request #60 from shurcooL/fix/fenced-code-block-extra-newline Fix for potential extra newline added inside fenced code blocks.
Vytautas Ĺ altenis vytas@rtfb.lt
Sat, 12 Apr 2014 21:58:08 +0300
2 files changed,
10 insertions(+),
2 deletions(-)
M
block_test.go
→
block_test.go
@@ -711,6 +711,12 @@ "<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>And some text after a fenced code block</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) }
M
markdown.go
→
markdown.go
@@ -330,9 +330,11 @@ }
if p.flags&EXTENSION_FENCED_CODE != 0 { // 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 { - out.WriteByte('\n') // need to inject additional linebreak + if !lastLineWasBlank { + out.WriteByte('\n') // need to inject additional linebreak + } lastFencedCodeBlockEnd = beg + i } }