Skip to content
This repository was archived by the owner on Feb 10, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- LVN Commands
- LiveViewNative.Template.Engine
- LiveViewNative.Component.Declarative
- Template parser supports namespaced attribute keys

### Changed

Expand Down
5 changes: 3 additions & 2 deletions lib/live_view_native/template/parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ defmodule LiveViewNative.Template.Parser do

@first_chars ~c"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
@chars ~c"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-"
@attribute_key @chars ++ ~c":"
@whitespace ~c"\s\t\n\r"
@entities [
{?<, "&lt;"},
Expand Down Expand Up @@ -283,13 +284,13 @@ defmodule LiveViewNative.Template.Parser do
parse_attribute_key(document, move_cursor(cursor, char), [char], args)
end

defp parse_attribute_key(<<char, _document::binary>> = document, cursor, key_buffer, _args) when char not in @chars do
defp parse_attribute_key(<<char, _document::binary>> = document, cursor, key_buffer, _args) when char not in @attribute_key do
key = List.to_string(key_buffer)

{:ok, {document, key, cursor}}
end

defp parse_attribute_key(<<char, document::binary>>, cursor, key_buffer, args) when char in @chars do
defp parse_attribute_key(<<char, document::binary>>, cursor, key_buffer, args) when char in @attribute_key do
parse_attribute_key(document, move_cursor(cursor, char), [key_buffer, char], args)
end

Expand Down
12 changes: 12 additions & 0 deletions test/live_view_native/template/parser_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,18 @@ defmodule LiveViewNative.Template.ParserTest do
end
end

test "supports namespaced attribute name" do
{:ok, nodes} = """
<FooBar
a:b="123"></FooBar>
"""
|> parse_document()

assert nodes == [
{"FooBar", [{"a:b", "123"}], []}
]
end

test "invalid attribute key name" do
doc = """
<FooBar
Expand Down