2023-12-12 23:38:43 +08:00
|
|
|
package parser
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/usememos/memos/plugin/gomark/ast"
|
|
|
|
"github.com/usememos/memos/plugin/gomark/parser/tokenizer"
|
|
|
|
)
|
|
|
|
|
|
|
|
type LineBreakParser struct{}
|
|
|
|
|
|
|
|
var defaultLineBreakParser = &LineBreakParser{}
|
|
|
|
|
|
|
|
func NewLineBreakParser() *LineBreakParser {
|
|
|
|
return defaultLineBreakParser
|
|
|
|
}
|
|
|
|
|
|
|
|
func (*LineBreakParser) Match(tokens []*tokenizer.Token) (int, bool) {
|
|
|
|
if len(tokens) == 0 {
|
|
|
|
return 0, false
|
|
|
|
}
|
|
|
|
if tokens[0].Type != tokenizer.Newline {
|
|
|
|
return 0, false
|
|
|
|
}
|
|
|
|
return 1, true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *LineBreakParser) Parse(tokens []*tokenizer.Token) ast.Node {
|
|
|
|
size, ok := p.Match(tokens)
|
|
|
|
if size == 0 || !ok {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-12-13 09:06:47 +08:00
|
|
|
return &ast.LineBreak{}
|
2023-12-12 23:38:43 +08:00
|
|
|
}
|