diff --git a/block.go b/block.go index 929638a..45c21a6 100644 --- a/block.go +++ b/block.go @@ -1143,6 +1143,7 @@ func (p *parser) listItem(out *bytes.Buffer, data []byte, flags *int) int { // process the following lines containsBlankLine := false sublist := 0 + codeBlockMarker := "" gatherlines: for line < len(data) { @@ -1170,6 +1171,28 @@ gatherlines: chunk := data[line+indent : i] + if p.flags&EXTENSION_FENCED_CODE != 0 { + // determine if in or out of codeblock + // if in codeblock, ignore normal list processing + _, marker := isFenceLine(chunk, nil, codeBlockMarker, false) + if marker != "" { + if codeBlockMarker == "" { + // start of codeblock + codeBlockMarker = marker + } else { + // end of codeblock. + *flags |= LIST_ITEM_CONTAINS_BLOCK + codeBlockMarker = "" + } + } + // we are in a codeblock, write line, and continue + if codeBlockMarker != "" || marker != "" { + raw.Write(data[line+indent : i]) + line = i + continue gatherlines + } + } + // evaluate how this line fits in switch { // is this a nested list item? diff --git a/block_test.go b/block_test.go index b9d6653..820fe89 100644 --- a/block_test.go +++ b/block_test.go @@ -1583,6 +1583,44 @@ func TestFencedCodeBlock_EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK(t *testing.T) { doTestsBlock(t, tests, EXTENSION_FENCED_CODE|EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK) } +func TestListWithFencedCodeBlock(t *testing.T) { + var tests = []string{ + "1. one\n\n ```\n code\n ```\n\n2. two\n", + "
one
\n\ncode\n
two
one
\n\n- code\n
two
one
\n\n\ncode\n
two
one
\n\n```
\n\ntwo