Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

chore: handle newline in block parsers

Steven6763dab4e50b
diff --git a/plugin/gomark/parser/heading.go b/plugin/gomark/parser/heading.go
index 1b228dbf4..284c88820 100644
--- a/plugin/gomark/parser/heading.go
+++ b/plugin/gomark/parser/heading.go
@@ -36,11 +36,11 @@ func (*HeadingParser) Match(tokens []*tokenizer.Token) (int, bool) {
cursor++
contentTokens := []*tokenizer.Token{}
for _, token := range tokens[cursor:] {
+ contentTokens = append(contentTokens, token)
+ cursor++
if token.Type == tokenizer.Newline {
break
}
- contentTokens = append(contentTokens, token)
- cursor++
}
if len(contentTokens) == 0 {
return 0, false
diff --git a/plugin/gomark/parser/heading_test.go b/plugin/gomark/parser/heading_test.go
index 759c1d18b..47cee835c 100644
--- a/plugin/gomark/parser/heading_test.go
+++ b/plugin/gomark/parser/heading_test.go
@@ -53,6 +53,7 @@ Hello World`,
&ast.Text{
Content: "123 ",
},
+ &ast.LineBreak{},
},
},
},
diff --git a/plugin/gomark/parser/horizontal_rule.go b/plugin/gomark/parser/horizontal_rule.go
index 0f104539b..a3db6d1d4 100644
--- a/plugin/gomark/parser/horizontal_rule.go
+++ b/plugin/gomark/parser/horizontal_rule.go
@@ -26,7 +26,10 @@ func (*HorizontalRuleParser) Match(tokens []*tokenizer.Token) (int, bool) {
if len(tokens) > 3 && tokens[3].Type != tokenizer.Newline {
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) {
diff --git a/plugin/gomark/parser/horizontal_rule_test.go b/plugin/gomark/parser/horizontal_rule_test.go
index 1cc34428b..d191ae8f5 100644
--- a/plugin/gomark/parser/horizontal_rule_test.go
+++ b/plugin/gomark/parser/horizontal_rule_test.go
@@ -20,6 +20,12 @@ func TestHorizontalRuleParser(t *testing.T) {
Symbol: "-",
},
},
+ {
+ text: "---\naaa",
+ horizontalRule: &ast.HorizontalRule{
+ Symbol: "-",
+ },
+ },
{
text: "****",
horizontalRule: nil,