feat(html): add lang helper
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-03 17:28:27 +00:00
parent 25dc761d0b
commit f8558a52ef
3 changed files with 17 additions and 0 deletions

View file

@ -38,6 +38,7 @@ Accessibility-oriented helpers are also provided for common attribute patterns:
- `AriaDescribedBy(node, ids...)`
- `AriaLabelledBy(node, ids...)`
- `Role(node, role)`
- `Lang(node, locale)`
- `Alt(node, text)`
- `AriaHidden(node, hidden)`
- `TabIndex(node, index)`

View file

@ -202,6 +202,12 @@ func Role(n Node, role string) Node {
return Attr(n, "role", role)
}
// node.go: Lang sets the lang attribute on an element node.
// Example: Lang(El("html"), "en-GB").
func Lang(n Node, locale string) Node {
return Attr(n, "lang", locale)
}
// node.go: Alt sets the alt attribute on an element node.
// Example: Alt(El("img"), "Product screenshot").
func Alt(n Node, text string) Node {

View file

@ -273,6 +273,16 @@ func TestRoleHelper(t *testing.T) {
}
}
func TestLangHelper(t *testing.T) {
ctx := NewContext()
node := Lang(El("html", Raw("content")), "en-GB")
got := node.Render(ctx)
want := `<html lang="en-GB">content</html>`
if got != want {
t.Errorf("Lang() = %q, want %q", got, want)
}
}
func TestAltHelper(t *testing.T) {
ctx := NewContext()
node := Alt(El("img"), `A "quoted" caption`)