From 04b07b3715a815f0140d870fb88a6822f06cf5cb Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Sat, 28 Oct 2023 02:23:11 +0200 Subject: Allow for true HTML ID- and class shorthands --- parser/parser.go | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'parser/parser.go') 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{} -- cgit v1.2.3