Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(parser): support colons in element names #723

Merged
merged 3 commits into from
May 8, 2024
Merged

feat(parser): support colons in element names #723

merged 3 commits into from
May 8, 2024

Conversation

deej-io
Copy link
Contributor

@deej-io deej-io commented May 3, 2024

I am using templ to generate HXML for a Hyperview app I am building (blog post about it coming soon 🤞).

HXML supports custom elements via a namespace - represented by a colon in the tag name.

I couldn't see anything in the HTML5 spec about whether this is valid, and I was worried how it would work with pseudo elements, but it does seem to be handled by browsers as per this example (tested in both Firefox and Chromium):

 <!DOCTYPE html>
<html>
<head>
	 <style>
		foo\:bar {color: red;}
		foo\:bar:hover {color: blue;}
	</style>
</head>
<body>

<div>
	<foo:bar>
		<h1>Hello</h2>
	</foo:bar>
</div>

</body>
</html>

@joerdav
Copy link
Collaborator

joerdav commented May 3, 2024

An element’s qualified name is its local name if its namespace prefix is null; otherwise its namespace prefix, followed by ":", followed by its local name.

Taken from: https://dom.spec.whatwg.org/#interface-element

Seems to be called an element prefix! https://developer.mozilla.org/en-US/docs/Web/API/Element/prefix

Looks good to me.

@joerdav
Copy link
Collaborator

joerdav commented May 3, 2024

I think we're correctly not parsing if the name starts with a colon, but it seems also not valid for it to end with a colon. But could be argued its not something templ should enforce?

@a-h a-h merged commit 7d8287e into a-h:main May 8, 2024
4 checks passed
@deej-io
Copy link
Contributor Author

deej-io commented May 8, 2024

Thanks for merging, folks!

@joerdav
Copy link
Collaborator

joerdav commented May 8, 2024

Looking forward to the blog post :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants