Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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("<br />")
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)

Expand Down
45 changes: 45 additions & 0 deletions block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
`<ul>
<li>One</li>
<li>Two</li>
</ul>

<p>Text</p>
`,

`* Double
line
* Single line

Text`,
`<ul>
<li>Double<br />
line</li>
<li>Single line</li>
</ul>

<p>Text</p>
`,

`1. One
2. Two

Text`,
`<ol>
<li>One</li>
<li>Two</li>
</ol>

<p>Text</p>
`,
}
doTestsBlock(t, tests, EXTENSION_HARD_LINE_BREAK)
}

func TestTitleBlock_EXTENSION_TITLEBLOCK(t *testing.T) {
var tests = []string{
"% Some title\n" +
Expand Down