2023-12-12 23:24:02 +08:00
|
|
|
package parser
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/usememos/memos/plugin/gomark/ast"
|
|
|
|
"github.com/usememos/memos/plugin/gomark/parser/tokenizer"
|
|
|
|
)
|
|
|
|
|
|
|
|
type TextParser struct {
|
|
|
|
Content string
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewTextParser() *TextParser {
|
2023-12-13 21:00:13 +08:00
|
|
|
return &TextParser{}
|
2023-12-12 23:24:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (*TextParser) Match(tokens []*tokenizer.Token) (int, bool) {
|
|
|
|
if len(tokens) == 0 {
|
|
|
|
return 0, false
|
|
|
|
}
|
|
|
|
return 1, true
|
|
|
|
}
|
|
|
|
|
2023-12-13 23:50:05 +08:00
|
|
|
func (*TextParser) Parse(tokens []*tokenizer.Token) (ast.Node, error) {
|
2023-12-12 23:24:02 +08:00
|
|
|
if len(tokens) == 0 {
|
2023-12-13 23:50:05 +08:00
|
|
|
return &ast.Text{}, nil
|
2023-12-13 09:06:47 +08:00
|
|
|
}
|
|
|
|
return &ast.Text{
|
|
|
|
Content: tokens[0].String(),
|
2023-12-13 23:50:05 +08:00
|
|
|
}, nil
|
2023-12-12 23:24:02 +08:00
|
|
|
}
|