From c53c1a4cfef09f165e949c59d8d865b0e40a75e0 Mon Sep 17 00:00:00 2001 From: Karel Bilek Date: Fri, 29 Jan 2021 15:51:01 +0700 Subject: [PATCH] Fix empty line detection in markdown in list Fix for independent issue in #177 The next parser should have the whitespace removed, even when it's blank --- _test/extra.txt | 88 +++++++++++++++++++++++++++++++++++++++++++++ parser/list.go | 2 ++ parser/list_item.go | 2 ++ 3 files changed, 92 insertions(+) diff --git a/_test/extra.txt b/_test/extra.txt index 7c95ca4..7b3ec0c 100644 --- a/_test/extra.txt +++ b/_test/extra.txt @@ -235,3 +235,91 @@ bbb //= = = = = = = = = = = = = = = = = = = = = = = =// + +17: fenced code block in list, empty line, spaces on start +//- - - - - - - - -// +* foo + ```Makefile + foo + + foo + ``` +//- - - - - - - - -// + +//= = = = = = = = = = = = = = = = = = = = = = = =// + +18: fenced code block in list, empty line, no spaces on start +//- - - - - - - - -// +* foo + ```Makefile + foo + + foo + ``` +//- - - - - - - - -// + +//= = = = = = = = = = = = = = = = = = = = = = = =// + + +19: fenced code block inside nested list, empty line, spaces on start +//- - - - - - - - -// +* foo + - bar + ```Makefile + foo + + foo + ``` +//- - - - - - - - -// + +//= = = = = = = = = = = = = = = = = = = = = = = =// + + +20: fenced code block inside nested list, empty line, no space on start +//- - - - - - - - -// +* foo + - bar + ```Makefile + foo + + foo + ``` +//- - - - - - - - -// + +//= = = = = = = = = = = = = = = = = = = = = = = =// diff --git a/parser/list.go b/parser/list.go index 9183a6d..4460282 100644 --- a/parser/list.go +++ b/parser/list.go @@ -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) return Continue | HasChildren } diff --git a/parser/list_item.go b/parser/list_item.go index 4a698d8..6c8db95 100644 --- a/parser/list_item.go +++ b/parser/list_item.go @@ -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 }