feat: image and link parser (#1744)

* feat: image and link parser

* chore: update
This commit is contained in:
boojack
2023-05-26 08:43:37 +08:00
committed by GitHub
parent 523ef2bba5
commit dbc85fe7e4
8 changed files with 252 additions and 18 deletions

View File

@ -3,12 +3,17 @@ package tokenizer
type TokenType = string
const (
Underline TokenType = "_"
Star TokenType = "*"
Hash TokenType = "#"
Backtick TokenType = "`"
Newline TokenType = "\n"
Space TokenType = " "
Underline TokenType = "_"
Star TokenType = "*"
Hash TokenType = "#"
Backtick TokenType = "`"
LeftSquareBracket TokenType = "["
RightSquareBracket TokenType = "]"
LeftParenthesis TokenType = "("
RightParenthesis TokenType = ")"
ExclamationMark TokenType = "!"
Newline TokenType = "\n"
Space TokenType = " "
)
const (
@ -37,10 +42,20 @@ func Tokenize(text string) []*Token {
tokens = append(tokens, NewToken(Star, "*"))
case '#':
tokens = append(tokens, NewToken(Hash, "#"))
case '\n':
tokens = append(tokens, NewToken(Newline, "\n"))
case '`':
tokens = append(tokens, NewToken(Backtick, "`"))
case '[':
tokens = append(tokens, NewToken(LeftSquareBracket, "["))
case ']':
tokens = append(tokens, NewToken(RightSquareBracket, "]"))
case '(':
tokens = append(tokens, NewToken(LeftParenthesis, "("))
case ')':
tokens = append(tokens, NewToken(RightParenthesis, ")"))
case '!':
tokens = append(tokens, NewToken(ExclamationMark, "!"))
case '\n':
tokens = append(tokens, NewToken(Newline, "\n"))
case ' ':
tokens = append(tokens, NewToken(Space, " "))
default: