mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
chore: handle newline in block parsers
This commit is contained in:
@@ -36,11 +36,11 @@ func (*HeadingParser) Match(tokens []*tokenizer.Token) (int, bool) {
|
|||||||
cursor++
|
cursor++
|
||||||
contentTokens := []*tokenizer.Token{}
|
contentTokens := []*tokenizer.Token{}
|
||||||
for _, token := range tokens[cursor:] {
|
for _, token := range tokens[cursor:] {
|
||||||
|
contentTokens = append(contentTokens, token)
|
||||||
|
cursor++
|
||||||
if token.Type == tokenizer.Newline {
|
if token.Type == tokenizer.Newline {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
contentTokens = append(contentTokens, token)
|
|
||||||
cursor++
|
|
||||||
}
|
}
|
||||||
if len(contentTokens) == 0 {
|
if len(contentTokens) == 0 {
|
||||||
return 0, false
|
return 0, false
|
||||||
|
@@ -53,6 +53,7 @@ Hello World`,
|
|||||||
&ast.Text{
|
&ast.Text{
|
||||||
Content: "123 ",
|
Content: "123 ",
|
||||||
},
|
},
|
||||||
|
&ast.LineBreak{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@@ -26,7 +26,10 @@ func (*HorizontalRuleParser) Match(tokens []*tokenizer.Token) (int, bool) {
|
|||||||
if len(tokens) > 3 && tokens[3].Type != tokenizer.Newline {
|
if len(tokens) > 3 && tokens[3].Type != tokenizer.Newline {
|
||||||
return 0, false
|
return 0, false
|
||||||
}
|
}
|
||||||
return 3, true
|
if len(tokens) == 3 {
|
||||||
|
return 3, true
|
||||||
|
}
|
||||||
|
return 4, true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *HorizontalRuleParser) Parse(tokens []*tokenizer.Token) (ast.Node, error) {
|
func (p *HorizontalRuleParser) Parse(tokens []*tokenizer.Token) (ast.Node, error) {
|
||||||
|
@@ -20,6 +20,12 @@ func TestHorizontalRuleParser(t *testing.T) {
|
|||||||
Symbol: "-",
|
Symbol: "-",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
text: "---\naaa",
|
||||||
|
horizontalRule: &ast.HorizontalRule{
|
||||||
|
Symbol: "-",
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
text: "****",
|
text: "****",
|
||||||
horizontalRule: nil,
|
horizontalRule: nil,
|
||||||
|
Reference in New Issue
Block a user