all repos — grayfriday @ 5bcdd5eb7f81a9db3e4e08ef88f150c4e70917c3

blackfriday fork with a few changes

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
commit

5bcdd5eb7f81a9db3e4e08ef88f150c4e70917c3

parent

c5ece173ad8a086a3ea27a54b0a2ee82028fb274

2 files changed, 10 insertions(+), 2 deletions(-)

jump to
M block_test.goblock_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.gomarkdown.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 } }