Skip to content

Commit

Permalink
fix: merge list nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyjoygh committed Sep 28, 2024
1 parent c9d3461 commit 9aca881
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
2 changes: 2 additions & 0 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ func mergeListItemNodes(nodes []ast.Node) []ast.Node {
}
} else {
result = append(result, node)
// Reset the stack if the current node is not a list item node.
stack = nil
}
}

Expand Down
60 changes: 60 additions & 0 deletions parser/tests/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,26 @@ func TestListParser(t *testing.T) {
text string
nodes []ast.Node
}{
{
text: "1. hello\n\n",
nodes: []ast.Node{
&ast.List{
Kind: ast.OrderedList,
Children: []ast.Node{
&ast.OrderedListItem{
Number: "1",
Children: []ast.Node{
&ast.Text{
Content: "hello",
},
},
},
&ast.LineBreak{},
&ast.LineBreak{},
},
},
},
},
{
text: "1. hello\n2. world",
nodes: []ast.Node{
Expand Down Expand Up @@ -164,6 +184,46 @@ func TestListParser(t *testing.T) {
},
},
},
{
text: "* hello\nparagraph\n* world",
nodes: []ast.Node{
&ast.List{
Kind: ast.UnorderedList,
Children: []ast.Node{
&ast.UnorderedListItem{
Symbol: "*",
Children: []ast.Node{
&ast.Text{
Content: "hello",
},
},
},
&ast.LineBreak{},
},
},
&ast.Paragraph{
Children: []ast.Node{
&ast.Text{
Content: "paragraph",
},
},
},
&ast.LineBreak{},
&ast.List{
Kind: ast.UnorderedList,
Children: []ast.Node{
&ast.UnorderedListItem{
Symbol: "*",
Children: []ast.Node{
&ast.Text{
Content: "world",
},
},
},
},
},
},
},
}

for _, test := range tests {
Expand Down

0 comments on commit 9aca881

Please sign in to comment.