diff --git a/block.go b/block.go index d7da33f..1f5ce64 100644 --- a/block.go +++ b/block.go @@ -1148,6 +1148,18 @@ func (p *Markdown) list(data []byte, flags ListType) int { return i } +// Returns true if the list item is not the same type as its parent list +func (p *Markdown) listTypeChanged(data []byte, flags *ListType) bool { + if p.dliPrefix(data) > 0 && *flags&ListTypeDefinition == 0 { + return true + } else if p.oliPrefix(data) > 0 && *flags&ListTypeOrdered == 0 { + return true + } else if p.uliPrefix(data) > 0 && (*flags&ListTypeOrdered != 0 || *flags&ListTypeDefinition != 0) { + return true + } + return false +} + // Returns true if block ends with a blank line, descending if needed // into lists and sublists. func endsWithBlankLine(block *Node) bool { @@ -1286,14 +1298,21 @@ gatherlines: p.oliPrefix(chunk) > 0 || p.dliPrefix(chunk) > 0: - if containsBlankLine { - *flags |= ListItemContainsBlock + // to be a nested list, it must be indented more + // if not, it is either a different kind of list + // or the next item in the same list + if indent <= itemIndent { + if p.listTypeChanged(chunk, flags) { + *flags |= ListItemEndOfList + } else if containsBlankLine { + *flags |= ListItemContainsBlock + } + + break gatherlines } - // to be a nested list, it must be indented more - // if not, it is the next item in the same list - if indent <= itemIndent { - break gatherlines + if containsBlankLine { + *flags |= ListItemContainsBlock } // is this the first item in the nested list? diff --git a/block_test.go b/block_test.go index 0a2a4d8..4d5e4f6 100644 --- a/block_test.go +++ b/block_test.go @@ -853,6 +853,17 @@ func TestDefinitionList(t *testing.T) { doTestsBlock(t, tests, DefinitionLists) } +func TestConsecutiveLists(t *testing.T) { + var tests = []string{ + "1. Hello\n\n* Hello\n\nTerm 1\n: Definition a\n", + "
    \n
  1. Hello
  2. \n
\n\n\n\n
\n
Term 1
\n
Definition a
\n
\n", + + "1. Not nested\n2. ordered list\n\n\t1. nested\n\t2. ordered list\n\n\t* nested\n\t* unordered list\n* Not nested\n* unordered list", + "
    \n
  1. Not nested

  2. \n\n
  3. ordered list

    \n\n
      \n
    1. nested
    2. \n
    3. ordered list
    4. \n
    \n\n
  4. \n
\n\n\n", + } + doTestsBlock(t, tests, DefinitionLists) +} + func TestPreformattedHtml(t *testing.T) { var tests = []string{ "
\n",