chore: fix math block matcher

This commit is contained in:
Steven 2024-01-04 21:50:13 +08:00
parent 9593b0b091
commit d7ed59581c
4 changed files with 24 additions and 2 deletions

View file

@ -74,7 +74,7 @@ func (n *BaseNode) SetNextSibling(node Node) {
func IsBlockNode(node Node) bool {
switch node.Type() {
case ParagraphNode, CodeBlockNode, HeadingNode, HorizontalRuleNode, BlockquoteNode, OrderedListNode, UnorderedListNode, TaskListNode:
case ParagraphNode, CodeBlockNode, HeadingNode, HorizontalRuleNode, BlockquoteNode, OrderedListNode, UnorderedListNode, TaskListNode, MathBlockNode:
return true
default:
return false

View file

@ -18,7 +18,7 @@ func (*MathBlockParser) Match(tokens []*tokenizer.Token) (int, bool) {
return 0, false
}
if tokens[0].Type != tokenizer.DollarSign && tokens[1].Type != tokenizer.DollarSign && tokens[2].Type != tokenizer.Newline {
if tokens[0].Type != tokenizer.DollarSign || tokens[1].Type != tokenizer.DollarSign || tokens[2].Type != tokenizer.Newline {
return 0, false
}

View file

@ -21,6 +21,12 @@ func TestMathBlockParser(t *testing.T) {
Content: "(1+x)^2",
},
},
{
text: "$$\na=3\n$$",
link: &ast.MathBlock{
Content: "a=3",
},
},
}
for _, test := range tests {
tokens := tokenizer.Tokenize(test.text)

View file

@ -197,6 +197,22 @@ func TestParser(t *testing.T) {
},
},
},
{
text: "\n\n",
nodes: []ast.Node{
&ast.LineBreak{},
&ast.LineBreak{},
},
},
{
text: "\n$$\na=3\n$$",
nodes: []ast.Node{
&ast.LineBreak{},
&ast.MathBlock{
Content: "a=3",
},
},
},
}
for _, test := range tests {