diff --git a/elementparser.go b/elementparser.go index d44d8036e..8a7b0eb2e 100644 --- a/elementparser.go +++ b/elementparser.go @@ -58,7 +58,12 @@ var elementCloseTagParser = parse.All(asElementCloseTag, ) // Attribute name. -var attributeNameParser = parse.StringUntil(parse.Rune('=')) +var attributeNameFirst = "abcdefghijklmnopqrstuvwxyz" +var attributeNameSubsequent = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-" +var attributeNameParser = parse.Then(parse.WithStringConcatCombiner, + parse.RuneIn(elementNameFirst), + parse.Many(parse.WithStringConcatCombiner, 0, 15, parse.RuneIn(elementNameSubsequent)), +) // Constant attribute. var attributeConstantValueParser = parse.StringUntil(parse.Rune('"')) @@ -270,7 +275,7 @@ func (p elementSelfClosingParser) Parse(pi parse.Input) parse.Result { parse.Rune('<'), elementNameParser, newAttributesParser().Parse, - parse.Optional(parse.WithStringConcatCombiner, whitespaceParser), + optionalWhitespaceParser, parse.String("/>"), )(pi) } diff --git a/templateparser_test.go b/templateparser_test.go index 325bbc925..5732be22b 100644 --- a/templateparser_test.go +++ b/templateparser_test.go @@ -349,6 +349,63 @@ func TestTemplateParser(t *testing.T) { }, }, }, + { + name: "template: inputs", + input: `{% templ Name(p Parameter) %} + + +{% endtempl %}`, + expected: Template{ + Name: Expression{ + Value: "Name", + Range: Range{ + From: Position{ + Index: 9, + Line: 1, + Col: 9, + }, + To: Position{ + Index: 12, + Line: 1, + Col: 12, + }, + }, + }, + Parameters: Expression{ + Value: "p Parameter", + Range: Range{ + From: Position{ + Index: 14, + Line: 1, + Col: 14, + }, + To: Position{ + Index: 25, + Line: 1, + Col: 25, + }, + }, + }, + Children: []Node{ + Element{ + Name: "input", + Attributes: []Attribute{ + ConstantAttribute{Name: "type", Value: "text"}, + ConstantAttribute{Name: "value", Value: "a"}, + }, + }, + Whitespace{Value: "\n"}, + Element{ + Name: "input", + Attributes: []Attribute{ + ConstantAttribute{Name: "type", Value: "text"}, + ConstantAttribute{Name: "value", Value: "b"}, + }, + }, + Whitespace{Value: "\n"}, + }, + }, + }, } for _, tt := range tests { tt := tt