From fc6236fc55676063c27d56d02aeab6caa1ef07f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vytautas=20=C5=A0altenis?= Date: Sat, 26 Dec 2015 20:18:22 +0200 Subject: [PATCH] Fix bug with gathering list item lines Instead of swallowing an empty line and then reintroducing it back again in certain cases, collect the list item body in an unaltered form and let the recursive parsing call sort things out. Fixes issue #228. --- block.go | 10 ++-------- block_test.go | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 8 deletions(-) diff --git a/block.go b/block.go index 7fb472e..740ad46 100644 --- a/block.go +++ b/block.go @@ -1153,6 +1153,7 @@ gatherlines: // and move on to the next line if p.isEmpty(data[line:i]) > 0 { containsBlankLine = true + raw.Write(data[line:i]) line = i continue } @@ -1220,17 +1221,10 @@ gatherlines: // a blank line means this should be parsed as a block case containsBlankLine: - raw.WriteByte('\n') *flags |= LIST_ITEM_CONTAINS_BLOCK } - // if this line was preceeded by one or more blanks, - // re-introduce the blank into the buffer - if containsBlankLine { - containsBlankLine = false - raw.WriteByte('\n') - - } + containsBlankLine = false // add the line into the working buffer without prefix raw.Write(data[line+indent : i]) diff --git a/block_test.go b/block_test.go index 60da6ca..f59268e 100644 --- a/block_test.go +++ b/block_test.go @@ -702,10 +702,41 @@ func TestUnorderedList(t *testing.T) { "* List\n\n * sublist\n\n normal text\n\n * another sublist\n", "\n", + + `* Foo + + bar + + qux +`, + ` +`, } doTestsBlock(t, tests, 0) } +func TestFencedCodeBlockWithinList(t *testing.T) { + doTestsBlock(t, []string{ + "* Foo\n\n ```\n bar\n\n qux\n ```\n", + ` +`, + }, EXTENSION_FENCED_CODE) +} + func TestOrderedList(t *testing.T) { var tests = []string{ "1. Hello\n", @@ -798,6 +829,26 @@ func TestOrderedList(t *testing.T) { "1. numbers\n1. are ignored\n", "
    \n
  1. numbers
  2. \n
  3. are ignored
  4. \n
\n", + + `1. Foo + + bar + + + + qux +`, + `
    +
  1. Foo

    + +
    bar
    +
    +
    +
    +qux
    +
  2. +
+`, } doTestsBlock(t, tests, 0) }