all repos — grayfriday @ c455fd41c6baf2f78fd7ff0aadc4e4b4d52698b0

blackfriday fork with a few changes

Fix consecutive lists of different kinds (#443)

* fixed consecutive lists
* used helper method and addressed flag setting
Mitchell Cohen mitch.cohen@me.com
Tue, 20 Mar 2018 15:50:35 -0400
commit

c455fd41c6baf2f78fd7ff0aadc4e4b4d52698b0

parent

cfdcce51965fe68951a5fa45454aa6278c3f9614

2 files changed, 35 insertions(+), 5 deletions(-)

jump to
M block.goblock.go

@@ -1148,6 +1148,18 @@ p.tip = above

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 @@ case (p.uliPrefix(chunk) > 0 && !p.isHRule(chunk)) ||

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 the next item in the same list + // 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 + } + + if containsBlankLine { + *flags |= ListItemContainsBlock } // is this the first item in the nested list?
M block_test.goblock_test.go

@@ -853,6 +853,17 @@ }

doTestsBlock(t, tests, DefinitionLists) } +func TestConsecutiveLists(t *testing.T) { + var tests = []string{ + "1. Hello\n\n* Hello\n\nTerm 1\n: Definition a\n", + "<ol>\n<li>Hello</li>\n</ol>\n\n<ul>\n<li>Hello</li>\n</ul>\n\n<dl>\n<dt>Term 1</dt>\n<dd>Definition a</dd>\n</dl>\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", + "<ol>\n<li><p>Not nested</p></li>\n\n<li><p>ordered list</p>\n\n<ol>\n<li>nested</li>\n<li>ordered list</li>\n</ol>\n\n<ul>\n<li>nested</li>\n<li>unordered list</li>\n</ul></li>\n</ol>\n\n<ul>\n<li>Not nested</li>\n<li>unordered list</li>\n</ul>\n", + } + doTestsBlock(t, tests, DefinitionLists) +} + func TestPreformattedHtml(t *testing.T) { var tests = []string{ "<div></div>\n",