diff options
author | Thomas Voss <mail@thomasvoss.com> | 2023-10-28 02:23:11 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2023-10-28 02:23:11 +0200 |
commit | 04b07b3715a815f0140d870fb88a6822f06cf5cb (patch) | |
tree | 633b92a23a37802aae83d5f5cd6047164500ab65 /parser/parser.go | |
parent | 024cd373e052db4193343b1eeb0767df98d7ea1e (diff) |
Allow for true HTML ID- and class shorthandsv2.0.0
Diffstat (limited to 'parser/parser.go')
-rw-r--r-- | parser/parser.go | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/parser/parser.go b/parser/parser.go index 648cfe7..b333506 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -255,7 +255,7 @@ loop: return nil, err } - if s, err := reader.parseNodeName(); err != nil { + if s, err := reader.parseShorthand(); err != nil { return nil, err } else { attr.Value = s @@ -298,6 +298,33 @@ loop: return attrs, nil } +// parseShorthand parses an ID- or class shorthand value. +func (reader *reader) parseShorthand() (string, error) { + sb := strings.Builder{} + + for { + r, err := reader.readRune() + if err != nil { + return "", err + } + + if unicode.IsSpace(r) { + break + } + sb.WriteRune(r) + } + + s := sb.String() + if len(s) == 0 { + return "", invalidSyntax{ + pos: reader.pos, + expected: "id- or class name", + found: "no value", + } + } + return s, nil +} + // parseString parses the double quoted strings used as attribute values. func (reader *reader) parseString() (string, error) { sb := strings.Builder{} |