From 7d8287e490d06b1bc64610e37f9f5d6120dd0108 Mon Sep 17 00:00:00 2001 From: "Daniel J. Rollins" <7419862+deej-io@users.noreply.github.com> Date: Wed, 8 May 2024 13:35:08 +0100 Subject: [PATCH] feat(parser): support colons in element names (#723) Co-authored-by: Adrian Hesketh Co-authored-by: Adrian Hesketh --- .version | 2 +- parser/v2/elementparser.go | 2 +- parser/v2/elementparser_test.go | 25 +++++++++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/.version b/.version index 8840c547b..91dbe0903 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -0.2.681 \ No newline at end of file +0.2.682 \ No newline at end of file diff --git a/parser/v2/elementparser.go b/parser/v2/elementparser.go index 18b12b6f9..f64990087 100644 --- a/parser/v2/elementparser.go +++ b/parser/v2/elementparser.go @@ -361,7 +361,7 @@ func (attributesParser) Parse(in *parse.Input) (attributes []Attribute, ok bool, // Element name. var ( elementNameFirst = "abcdefghijklmnopqrstuvwxyz" - elementNameSubsequent = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-" + elementNameSubsequent = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-:" elementNameParser = parse.Func(func(in *parse.Input) (name string, ok bool, err error) { start := in.Index() var prefix, suffix string diff --git a/parser/v2/elementparser_test.go b/parser/v2/elementparser_test.go index 6bb695aa3..1399ae9a3 100644 --- a/parser/v2/elementparser_test.go +++ b/parser/v2/elementparser_test.go @@ -41,6 +41,31 @@ func TestAttributeParser(t *testing.T) { }, }, }, + { + name: "element: colon in name", + input: ``, + parser: StripType(elementOpenTagParser), + expected: elementOpenTag{ + Name: "maps:map", + NameRange: Range{ + From: Position{Index: 1, Line: 0, Col: 1}, + To: Position{Index: 9, Line: 0, Col: 9}, + }, + }, + }, + { + name: "element: colon in name, closing", + input: `Content`, + parser: StripType(element), + expected: Element{ + Name: "maps:map", + NameRange: Range{ + From: Position{Index: 1, Line: 0, Col: 1}, + To: Position{Index: 9, Line: 0, Col: 9}, + }, + Children: []Node{Text{Value: "Content"}}, + }, + }, { name: "element: open with hyperscript attribute", input: `
`,