Commit d7ed5958 authored by Steven's avatar Steven

chore: fix math block matcher

parent 9593b0b0
...@@ -74,7 +74,7 @@ func (n *BaseNode) SetNextSibling(node Node) { ...@@ -74,7 +74,7 @@ func (n *BaseNode) SetNextSibling(node Node) {
func IsBlockNode(node Node) bool { func IsBlockNode(node Node) bool {
switch node.Type() { switch node.Type() {
case ParagraphNode, CodeBlockNode, HeadingNode, HorizontalRuleNode, BlockquoteNode, OrderedListNode, UnorderedListNode, TaskListNode: case ParagraphNode, CodeBlockNode, HeadingNode, HorizontalRuleNode, BlockquoteNode, OrderedListNode, UnorderedListNode, TaskListNode, MathBlockNode:
return true return true
default: default:
return false return false
......
...@@ -18,7 +18,7 @@ func (*MathBlockParser) Match(tokens []*tokenizer.Token) (int, bool) { ...@@ -18,7 +18,7 @@ func (*MathBlockParser) Match(tokens []*tokenizer.Token) (int, bool) {
return 0, false 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 return 0, false
} }
......
...@@ -21,6 +21,12 @@ func TestMathBlockParser(t *testing.T) { ...@@ -21,6 +21,12 @@ func TestMathBlockParser(t *testing.T) {
Content: "(1+x)^2", Content: "(1+x)^2",
}, },
}, },
{
text: "$$\na=3\n$$",
link: &ast.MathBlock{
Content: "a=3",
},
},
} }
for _, test := range tests { for _, test := range tests {
tokens := tokenizer.Tokenize(test.text) tokens := tokenizer.Tokenize(test.text)
......
...@@ -197,6 +197,22 @@ func TestParser(t *testing.T) { ...@@ -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 { for _, test := range tests {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment