paragraph.go 631 B

123456789101112131415161718192021222324252627282930
  1. package parser
  2. import "github.com/usememos/memos/plugin/gomark/parser/tokenizer"
  3. type ParagraphParser struct {
  4. ContentTokens []*tokenizer.Token
  5. }
  6. func NewParagraphParser() *ParagraphParser {
  7. return &ParagraphParser{}
  8. }
  9. func (*ParagraphParser) Match(tokens []*tokenizer.Token) *ParagraphParser {
  10. contentTokens := []*tokenizer.Token{}
  11. cursor := 0
  12. for ; cursor < len(tokens); cursor++ {
  13. token := tokens[cursor]
  14. if token.Type == tokenizer.Newline {
  15. break
  16. }
  17. contentTokens = append(contentTokens, token)
  18. }
  19. if len(contentTokens) == 0 {
  20. return nil
  21. }
  22. return &ParagraphParser{
  23. ContentTokens: contentTokens,
  24. }
  25. }