diff --git a/block.go b/block.go index 563cb290..98d887bb 100644 --- a/block.go +++ b/block.go @@ -1305,9 +1305,29 @@ gatherlines: cookedBytes := cooked.Bytes() parsedEnd := len(cookedBytes) - // strip trailing newlines - for parsedEnd > 0 && cookedBytes[parsedEnd-1] == '\n' { - parsedEnd-- + if p.flags&EXTENSION_HARD_LINE_BREAK != 0 { + // strip trailing newlines and extra hard line breaks + const brLen = len("
") + for parsedEnd > 0 && + (cookedBytes[parsedEnd-1] == '\n' || + (parsedEnd >= brLen && + cookedBytes[parsedEnd-brLen] == '<' && + cookedBytes[parsedEnd-brLen+1] == 'b' && + cookedBytes[parsedEnd-brLen+2] == 'r' && + cookedBytes[parsedEnd-brLen+3] == ' ' && + cookedBytes[parsedEnd-brLen+4] == '/' && + cookedBytes[parsedEnd-brLen+5] == '>')) { + if cookedBytes[parsedEnd-1] == '\n' { + parsedEnd-- + } else { + parsedEnd -= brLen + } + } + } else { + // strip trailing newlines + for parsedEnd > 0 && cookedBytes[parsedEnd-1] == '\n' { + parsedEnd-- + } } p.r.ListItem(out, cookedBytes[:parsedEnd], *flags) diff --git a/block_test.go b/block_test.go index f2d998df..66fa73d1 100644 --- a/block_test.go +++ b/block_test.go @@ -1636,6 +1636,51 @@ func TestListWithFencedCodeBlockNoExtensions(t *testing.T) { doTestsBlock(t, tests, 0) } +func TestListEXTENSION_HARD_LINE_BREAK(t *testing.T) { + // If there is a fenced code block in a list, and FencedCode is not set, + // lists should be processed normally. + var tests = []string{ + `* One +* Two + +Text`, + ` + +

Text

+`, + + `* Double +line +* Single line + +Text`, + ` + +

Text

+`, + + `1. One +2. Two + +Text`, + `
    +
  1. One
  2. +
  3. Two
  4. +
+ +

Text

+`, + } + doTestsBlock(t, tests, EXTENSION_HARD_LINE_BREAK) +} + func TestTitleBlock_EXTENSION_TITLEBLOCK(t *testing.T) { var tests = []string{ "% Some title\n" +