Skip to content
Merged
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
6 changes: 6 additions & 0 deletions block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ func TestCodeInList(t *testing.T) {
doTestsParam(t, tests, TestParams{extensions: exts})
}

func TestBug346(t *testing.T) {
tests := readTestFile2(t, "bug346.tests")
exts := parser.CommonExtensions
doTestsParam(t, tests, TestParams{extensions: exts})
}

func TestLists(t *testing.T) {
tests := readTestFile2(t, "Lists.tests")
exts := parser.CommonExtensions
Expand Down
36 changes: 36 additions & 0 deletions parser/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -1409,6 +1409,9 @@ func (p *Parser) listItem(data []byte, flags *ast.ListType) int {
// process the following lines
containsBlankLine := false
sublist := 0
// track fenced code blocks inside list items so that lines within
// the fence are gathered verbatim (not misinterpreted as list items)
fenceMarker := ""

gatherlines:
for line < len(data) {
Expand Down Expand Up @@ -1442,6 +1445,39 @@ gatherlines:

chunk := data[line+indentIndex : i]

// track fenced code blocks inside list items;
// only track fences that are indented (part of the list item content),
// a fence at indent 0 ends the list (handled below)
if !isDefinitionList && p.extensions&FencedCode != 0 {
if fenceMarker != "" {
if indent == 0 {
// non-indented line while inside a fence means we
// left the list item content -- abandon the fence
fenceMarker = ""
} else {
// inside a fence: check for closing fence
_, marker := isFenceLine(chunk, nil, fenceMarker)
if marker != "" {
fenceMarker = ""
}
// gather the line verbatim, skip structure detection
if containsBlankLine {
containsBlankLine = false
raw.WriteByte('\n')
}
raw.Write(chunk)
line = i
continue
}
} else if indent > 0 {
// not inside a fence: check for opening fence (indented only)
_, marker := isFenceLine(chunk, nil, "")
if marker != "" {
fenceMarker = marker
}
}
}

// If there is a fence line (marking starting of a code block)
// without indent do not process it as part of the list.
//
Expand Down
86 changes: 86 additions & 0 deletions testdata/bug346.tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
- test1

```
- test
```
- test2

```
- test
```
- test3

```
- test
```
+++
<ul>
<li><p>test1</p>

<pre><code>- test
</code></pre></li>

<li><p>test2</p>

<pre><code> - test
</code></pre></li>

<li><p>test3</p>

<pre><code> - test
</code></pre></li>
</ul>
+++
- item

```
1. not a list
```
+++
<ul>
<li><p>item</p>

<pre><code>1. not a list
</code></pre></li>
</ul>
+++
- item

```
# not a heading
```
+++
<ul>
<li><p>item</p>

<pre><code># not a heading
</code></pre></li>
</ul>
+++
- item

~~~
- dash in tilde fence
~~~
+++
<ul>
<li><p>item</p>

<pre><code>- dash in tilde fence
</code></pre></li>
</ul>
+++
- item1

```
- should be code
- item2
+++
<ul>
<li><p>item1</p>

<p>```
- should be code</p></li>

<li><p>item2</p></li>
</ul>