mirror of
https://github.com/usememos/memos.git
synced 2024-12-26 04:42:54 +03:00
31 lines
631 B
Go
31 lines
631 B
Go
|
package parser
|
||
|
|
||
|
import "github.com/usememos/memos/plugin/gomark/parser/tokenizer"
|
||
|
|
||
|
type ParagraphParser struct {
|
||
|
ContentTokens []*tokenizer.Token
|
||
|
}
|
||
|
|
||
|
func NewParagraphParser() *ParagraphParser {
|
||
|
return &ParagraphParser{}
|
||
|
}
|
||
|
|
||
|
func (*ParagraphParser) Match(tokens []*tokenizer.Token) *ParagraphParser {
|
||
|
contentTokens := []*tokenizer.Token{}
|
||
|
cursor := 0
|
||
|
for ; cursor < len(tokens); cursor++ {
|
||
|
token := tokens[cursor]
|
||
|
if token.Type == tokenizer.Newline {
|
||
|
break
|
||
|
}
|
||
|
contentTokens = append(contentTokens, token)
|
||
|
}
|
||
|
if len(contentTokens) == 0 {
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
return &ParagraphParser{
|
||
|
ContentTokens: contentTokens,
|
||
|
}
|
||
|
}
|