From 12fbb0035c85f44345dbddc11305a2f8397c161c Mon Sep 17 00:00:00 2001 From: "Daniel J. Rollins" Date: Fri, 3 May 2024 11:50:36 +0100 Subject: [PATCH 1/2] feat(parser): support colons in element names Colon is sometimes used for namespaces in elements such as in [HXML](https://hyperview.org/docs/reference_custom_elements#using-in-hxml) --- parser/v2/elementparser.go | 2 +- parser/v2/elementparser_test.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) 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..26a277eb5 100644 --- a/parser/v2/elementparser_test.go +++ b/parser/v2/elementparser_test.go @@ -41,6 +41,18 @@ 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: open with hyperscript attribute", input: `
`, From dd733bb6b0de74805e720eedf4af31b35b7a73a6 Mon Sep 17 00:00:00 2001 From: Adrian Hesketh Date: Wed, 8 May 2024 13:33:45 +0100 Subject: [PATCH 2/2] feat: add additional test --- .version | 2 +- parser/v2/elementparser_test.go | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/.version b/.version index fe4758d9e..91dbe0903 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -0.2.670 \ No newline at end of file +0.2.682 \ No newline at end of file diff --git a/parser/v2/elementparser_test.go b/parser/v2/elementparser_test.go index 26a277eb5..1399ae9a3 100644 --- a/parser/v2/elementparser_test.go +++ b/parser/v2/elementparser_test.go @@ -53,6 +53,19 @@ func TestAttributeParser(t *testing.T) { }, }, }, + { + 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: `
`,