Skip to content

Commit 9aca881

Browse files
committed
fix: merge list nodes
1 parent c9d3461 commit 9aca881

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

parser/parser.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ func mergeListItemNodes(nodes []ast.Node) []ast.Node {
151151
}
152152
} else {
153153
result = append(result, node)
154+
// Reset the stack if the current node is not a list item node.
155+
stack = nil
154156
}
155157
}
156158

parser/tests/list_test.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,26 @@ func TestListParser(t *testing.T) {
1616
text string
1717
nodes []ast.Node
1818
}{
19+
{
20+
text: "1. hello\n\n",
21+
nodes: []ast.Node{
22+
&ast.List{
23+
Kind: ast.OrderedList,
24+
Children: []ast.Node{
25+
&ast.OrderedListItem{
26+
Number: "1",
27+
Children: []ast.Node{
28+
&ast.Text{
29+
Content: "hello",
30+
},
31+
},
32+
},
33+
&ast.LineBreak{},
34+
&ast.LineBreak{},
35+
},
36+
},
37+
},
38+
},
1939
{
2040
text: "1. hello\n2. world",
2141
nodes: []ast.Node{
@@ -164,6 +184,46 @@ func TestListParser(t *testing.T) {
164184
},
165185
},
166186
},
187+
{
188+
text: "* hello\nparagraph\n* world",
189+
nodes: []ast.Node{
190+
&ast.List{
191+
Kind: ast.UnorderedList,
192+
Children: []ast.Node{
193+
&ast.UnorderedListItem{
194+
Symbol: "*",
195+
Children: []ast.Node{
196+
&ast.Text{
197+
Content: "hello",
198+
},
199+
},
200+
},
201+
&ast.LineBreak{},
202+
},
203+
},
204+
&ast.Paragraph{
205+
Children: []ast.Node{
206+
&ast.Text{
207+
Content: "paragraph",
208+
},
209+
},
210+
},
211+
&ast.LineBreak{},
212+
&ast.List{
213+
Kind: ast.UnorderedList,
214+
Children: []ast.Node{
215+
&ast.UnorderedListItem{
216+
Symbol: "*",
217+
Children: []ast.Node{
218+
&ast.Text{
219+
Content: "world",
220+
},
221+
},
222+
},
223+
},
224+
},
225+
},
226+
},
167227
}
168228

169229
for _, test := range tests {

0 commit comments

Comments
 (0)