Skip to content

Commit 73af9d7

Browse files
committed
HTML: return text and template tokens separately in lexer
1 parent ac9536c commit 73af9d7

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

html/lex.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const (
2323
TextToken
2424
SvgToken
2525
MathToken
26+
TemplateToken
2627
)
2728

2829
// String returns the string representation of a TokenType.
@@ -185,18 +186,19 @@ func (l *Lexer) Next() (TokenType, []byte) {
185186
} else if c == '!' {
186187
l.r.Move(2)
187188
return l.readMarkup()
188-
} else if 0 < len(l.tmplBegin) && l.at(l.tmplBegin...) {
189-
l.r.Move(len(l.tmplBegin))
190-
l.moveTemplate()
191-
l.hasTmpl = true
192189
} else if c == '?' {
193190
l.r.Move(1)
194191
return CommentToken, l.shiftBogusComment()
195192
}
196193
} else if 0 < len(l.tmplBegin) && l.at(l.tmplBegin...) {
194+
if 0 < l.r.Pos() {
195+
l.text = l.r.Shift()
196+
return TextToken, l.text
197+
}
197198
l.r.Move(len(l.tmplBegin))
198199
l.moveTemplate()
199200
l.hasTmpl = true
201+
return TemplateToken, l.r.Shift()
200202
} else if c == 0 && l.r.Err() != nil {
201203
if 0 < l.r.Pos() {
202204
l.text = l.r.Shift()

0 commit comments

Comments
 (0)