mirror of https://github.com/usememos/memos
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
860 B
Go
40 lines
860 B
Go
package parser
|
|
|
|
import (
|
|
"github.com/usememos/memos/plugin/gomark/ast"
|
|
"github.com/usememos/memos/plugin/gomark/parser/tokenizer"
|
|
)
|
|
|
|
type SubscriptParser struct{}
|
|
|
|
func NewSubscriptParser() *SubscriptParser {
|
|
return &SubscriptParser{}
|
|
}
|
|
|
|
func (*SubscriptParser) Match(tokens []*tokenizer.Token) (ast.Node, int) {
|
|
matchedTokens := tokenizer.GetFirstLine(tokens)
|
|
if len(matchedTokens) < 3 {
|
|
return nil, 0
|
|
}
|
|
if matchedTokens[0].Type != tokenizer.Tilde {
|
|
return nil, 0
|
|
}
|
|
|
|
contentTokens := []*tokenizer.Token{}
|
|
matched := false
|
|
for _, token := range matchedTokens[1:] {
|
|
if token.Type == tokenizer.Tilde {
|
|
matched = true
|
|
break
|
|
}
|
|
contentTokens = append(contentTokens, token)
|
|
}
|
|
if !matched || len(contentTokens) == 0 {
|
|
return nil, 0
|
|
}
|
|
|
|
return &ast.Subscript{
|
|
Content: tokenizer.Stringify(contentTokens),
|
|
}, len(contentTokens) + 2
|
|
}
|