mirror of
https://github.com/usememos/memos.git
synced 2024-12-27 15:42:51 +08:00
chore: fix math block matcher
This commit is contained in:
parent
9593b0b091
commit
d7ed59581c
4 changed files with 24 additions and 2 deletions
|
@ -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) {
|
||||||
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) {
|
||||||
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) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
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 {
|
||||||
|
|
Loading…
Reference in a new issue