Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix empty line detection in markdown in list #188

Merged
merged 1 commit into from
Mar 26, 2021
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
88 changes: 88 additions & 0 deletions _test/extra.txt
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,91 @@ bbb
</li>
</ul>
//= = = = = = = = = = = = = = = = = = = = = = = =//

17: fenced code block in list, empty line, spaces on start
//- - - - - - - - -//
* foo
```Makefile
foo

foo
```
//- - - - - - - - -//
<ul>
<li>foo
<pre><code class="language-Makefile">foo

foo
</code></pre>
</li>
</ul>
//= = = = = = = = = = = = = = = = = = = = = = = =//

18: fenced code block in list, empty line, no spaces on start
//- - - - - - - - -//
* foo
```Makefile
foo

foo
```
//- - - - - - - - -//
<ul>
<li>foo
<pre><code class="language-Makefile">foo

foo
</code></pre>
</li>
</ul>
//= = = = = = = = = = = = = = = = = = = = = = = =//


19: fenced code block inside nested list, empty line, spaces on start
//- - - - - - - - -//
* foo
- bar
```Makefile
foo

foo
```
//- - - - - - - - -//
<ul>
<li>foo
<ul>
<li>bar
<pre><code class="language-Makefile">foo

foo
</code></pre>
</li>
</ul>
</li>
</ul>
//= = = = = = = = = = = = = = = = = = = = = = = =//


20: fenced code block inside nested list, empty line, no space on start
//- - - - - - - - -//
* foo
- bar
```Makefile
foo

foo
```
//- - - - - - - - -//
<ul>
<li>foo
<ul>
<li>bar
<pre><code class="language-Makefile">foo

foo
</code></pre>
</li>
</ul>
</li>
</ul>
//= = = = = = = = = = = = = = = = = = = = = = = =//
2 changes: 2 additions & 0 deletions parser/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ func (b *listParser) Continue(node ast.Node, reader text.Reader, pc Context) Sta
if node.ChildCount() == 1 && node.LastChild().ChildCount() == 0 {
return Close
}

reader.Advance(len(line)-1)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: A comment explaining "why" would be helpful here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm I already forgot :D it would get me a while to get into this

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😆 That's why I write the "why" comments

return Continue | HasChildren
}

Expand Down
2 changes: 2 additions & 0 deletions parser/list_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ func (b *listItemParser) Open(parent ast.Node, reader text.Reader, pc Context) (
func (b *listItemParser) Continue(node ast.Node, reader text.Reader, pc Context) State {
line, _ := reader.PeekLine()
if util.IsBlank(line) {
reader.Advance(len(line)-1)

return Continue | HasChildren
}

Expand Down