htm

package module
v0.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 3, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

README

htm

GoDoc License

This package should be considered experimental.

A relatively fast, zero-allocation HTML tree builder and renderer for Go.

It provides a Node type with a chaining method API and an optional functional API that simplifies composition. While fully capable of direct use, its primary goal is to serve as a foundation for higher-level DSLs and component frameworks.

Goals
  • Build and render HTML trees with very low overhead.
  • Be a good backend for DSLs (component frameworks, templates, code generators).
  • Enable composition and extensibility via functional API.
  • Make performance characteristics explicit.

Non-goals:

  • Being a complete web framework.
  • Hiding all footguns.

Quick start

Methods API

Direct method chaining is the most performant way to build trees:

root := htm.Div().
    ID("container").
    Class("flex column").
    Content(
        htm.H1().
            Text("Hello, World!"),
        htm.Button().
            OnClick("alert('clicked')").
            Disabled().
            Text("Click Me"),
    )

defer root.Release()

_ = root.Render(os.Stdout)
Functional API

Mods (or modifiers) are functions with the signature func(*Node). This is primarily about extensibility and composition. It allows to define custom logic and higher-level abstractions in separate packages.

root := htm.Div(
    htm.ID("container"),
    htm.Class("flex column"),
    htm.Content(
        htm.H1(htm.Content(
            htm.Text("Hello, World!"),
        )),
        htm.Button(
            aria.Label("button"),
            htm.OnClick("alert('clicked')")
            Content(htm.Text("Click Me")),
        ),
    ))

defer root.Release()

_ = root.Render(os.Stdout)

Building component frameworks on top

A component layer can be built on top of htm by defining constructors and modifiers in your own packages.

// package ui

func Button(mods ...htm.Mod) *htm.Node {
    return htm.Button().
        Class("btn").
        Apply(mods)
}

func Primary() htm.Mod {
    return htm.Class("btn-primary")
}

func SetFoo(v string) htm.Mod {
    return func(n *htm.Node) {
        n.Attr("foo", htm.String(v))
    }
}

// etc.

Usage:

btn := ui.Button(ui.Primary(), htm.Content(
    htm.Text("Save"),
))

// or
btn := ui.Button(ui.Primary(), htm.TextContent("Save"))
// or
btn := ui.Button(ui.Primary()).Text("Save")
// or
btn := ui.Button().Text("Save").Mod(ui.Primary())
// or
btn := ui.Button(SetFoo("bar")).Text("Save").Mod(ui.Primary())
// etc.

This gives "components" that can be combined into higher level building blocks.

Custom variables

The package allows attaching custom variables to nodes. These variables are not rendered and are used only during tree construction.

func Btn(mods ...htm.Mod) *htm.Node {
    return htm.Button().
        Class("htm-btn").
        Apply(mods).
        DefaultContent(func(n *htm.Node) {
            doSomething(n)
            if icon := n.GetVar("icon").StringOrZero(); icon != "" {
                n.Append(IconFn(icon).Class("htm-btn-icon"))
            }
            if caption := n.GetVar("caption").StringOrZero(); caption != "" {
                n.Append(htm.Span().Class("htm-btn-caption").Text(caption))
            }
        })
}

btn := Btn().Var("caption", "Save").Var("icon", "save")
Slots

Slots provide a way to pass dynamic content into components.

func Btn(mods ...htm.Mod) *htm.Node {
    return htm.Button().
        Class("my-btn").
        Apply(mods).
        Postpone(func(n *htm.Node) {
            n.Prepend(n.ExtractSlot("icon"))
        })
}

btn := Btn().Slot("icon", mysvg.Icon("close")))
Other useful notes

Everything can be overwritten / replaced:

htm.A().Href("#").Href("#abc") // result is "#abc"
htm.Button().Class("a b c").RemoveClass("a") // result is "b c"
htm.Button().Content(Span()).Content(Div()) // result is div
htm.Button().Content(Span()).Prepend(Div()) // result is div and span

card := ui.Card().Slot("footer", htm.Div(), htm.Span())
card.Slot("footer", htm.Button()) // footer now contains only a button
card.AppendSlot("footer", htm.Div()) // footer now contains a button and a div

Mod functions can be used directly from types:

func (t *MyType) LocalizedLabel(n *htm.Node) { ... }
// ...
htm.Button(t.LocalizedLabel)

A mod can be postponed until rendering to allow other things to happen:

htm.Div(func (n *htm.Node) {
  n.Postpone(mod1, mod2)
  n.Postpone(func (n *htm.Node) { ... })
})

For complex operations it is often more performant to do everything inside a single mod:

htm.Div(func (n *htm.Node) {
    n.Attr(...)
    n.Class(...)
    doThing(n)
    n.DefaultContent(...)
    doOtherThing(n)
    // etc.
})

Functions returning two values can be used directly:

func MyProp(...) (string, string) { return "my-prop", "example" }

htm.Div().Attr(MyProp())

Static rendering

The package provides a helper to render a subtree once and cache the result.

node := htm.Div().StaticContent(func() *htm.Node {
    // this runs once, the result is cached as raw bytes
    return htm.Group(
        htm.Span().Class("icon").Text("🌟"),
        htm.Span().Class("label").Text("Brand"),
    )
})

You can also define static fragments globally:

var logo = htm.Static(func() *htm.Node {
    return htm.Group(
        htm.Span(htm.Class("icon"), htm.Text("🌟")),
        htm.Span(htm.Class("label"), htm.Text("Brand")),
    )
}).Own() // prevents returning the node to the pool

func RenderHeader() *htm.Node {
    return htm.Div(
        htm.Tag("header")
        htm.Content(logo), // uses cached bytes
    )
}

Caching is done by using the function pointer as a key, closures are therefore executed at most once, regardless of captured variables.

Typed Values

To avoid allocations occurring when using any, the package provides strongly typed value helpers.

htm.Input().Value(htm.Int(42))

Many attribute helpers also accept typed arguments directly:

htm.Input().TabIndex(1)

Strings by default

Most methods accept a string by default:

n.Attr("name", "value")
n.Var("name", "value")
n.Text("hello")

htm.Attr("name", "value")
htm.Var("name", "value")
htm.Text("hello")

For other values, variants are available:

n.AttrValue("name", htm.Int(-42))
n.AttrValue("name", htm.Uint(100))
n.AttrValue("name", htm.Bool(false)) // unsets attribute
n.AttrValue("name", htm.JSON(myStruct)) // rendered as escaped JSON
n.AttrValue("name", htm.Float(3.14))

n.TextValue(htm.Int(42))
htm.TextValue(htm.Int(42))

Tags & Attribute Helpers

The package includes a large set of helper functions for standard HTML tags and attributes.
Please refer to the documentation for a complete list.

Safety notes

  • Text nodes and attribute values are HTML-escaped by default.

  • Raw nodes write bytes directly without escaping.

  • JavaScript and CSS can be rendered as raw bytes; no sanitization is currently performed.

Sub-packages

The module includes sub-packages for integration with popular frontend libraries and tools:

  • aria: Helpers for ARIA attributes
  • hx: Helpers for htmx attributes (hx-get, hx-swap, etc.)
  • ax: Helpers for Alpine.js directives (x-data, x-bind, etc.)
  • svg: Example implementation of helpers for SVG icons and images.

Design & Trade-offs

This library is oriented towards performance. It utilizes a custom pooling strategy and extensive use of unsafe for string/byte manipulation. Some ideas are taken from slog to avoid a so-called "interface boxing".

Pooling and Lifecycle

Nodes are pooled by default to reduce GC pressure.
The following contract should be respected:

  • Release only the root: call Release only on the root node.
    Package automatically handles the recursive release of all child nodes, attributes, and connected structures. Calling release on an already released node will result in panic or a corrupted pool.
  • Do not use same nodes twice: this leads to double-release.
    node := htm.Span()
    htm.Div().Content(
        node,
        htm.Div().Content(node), // this will corrupt the pool
    )
    
    If you need to render the same node multiple times, use owned nodes (see Own).
    You can also disable automatic pooling and manage the node lifecycle yourself.
  • Do not reuse released nodes: once released, a node may be immediately reused by another goroutine.

Nodes can be marked as "owned" to prevent them from being returned to the pool (and prevent their subtree from being pooled). This might be useful for long-lived fragments or custom pooling strategies.

Automatic pooling can be completely disabled by setting NoPool.

Memory Footprint

Package optimizes for runtime performance rather than memory efficiency. Some internal structures trade memory for speed or simplicity (e.g. keeping order-preserving attribute storage). If you need the smallest possible memory footprint, you may want to benchmark and/or consider alternative approaches.

Functional API Trade-offs

While the functional API enables composition, it can be slightly less efficient due to more function calls and allocation of values captured by closures. However, in many real-world cases (constants, inlining, pre-allocated pointers, non-capturing functions), this overhead is negligible.

Parsing

Package contains an HTML parser to build a node tree from the provided input.

n, err := htm.Parse(data, flags)

Available flags:

  • ParseReuseBuffer - parsed strings/bytes may reference the input buffer (zero allocations)
  • ParseKeepWhitespace - keep all whitespace text nodes
  • ParseKeepEdgeWhitespace - keep non-empty text nodes as-is, ignore whitespace-only text nodes
  • ParseKeepComments - keep comment nodes (<!-- ... -->) as raw nodes
  • ParseAllowScriptContent - allow non-empty <script> content
  • ParseTopLevelRawContent - parse exactly one top-level node and store its full inner HTML as one raw child node

Default behavior (no flags):

  • ParseReuseBuffer is disabled
  • Whitespace outside whitespace-sensitive tags is ignored
  • Comments are ignored
  • Non-empty <script> content is not allowed

Whitespace flag precedence:

  • ParseKeepWhitespace overrides ParseKeepEdgeWhitespace
  • If neither whitespace flag is set, parser removes whitespace-only segments and trims leading/trailing whitespace where applicable

Benchmarks

There are several benchmarks in the test files, but for a realistic assessment, it is always better to build and test your own trees.

htm.Div().Class("flex flex-col items-center p-7 rounded-2xl").Attr("id", "test").Content(
    htm.Span().Class("a b c").Text("hello"),
    htm.Span().Attr("data-x", "1").Text("world"),
)

Building and rendering the tree above on a laptop takes:

Benchmark_Build-16                   4029265     294.8 ns/op      0 B/op     0 allocs/op
Benchmark_Render/Default-16          4277874     282.6 ns/op      0 B/op     0 allocs/op
Benchmark_BuildRender/Default-16     1980176     606.2 ns/op      0 B/op     0 allocs/op

A page with header, footer and a table with 100 rows (~1400 nodes, see htm_test.go):

Benchmark_Page_Build-16                10000    114562 ns/op    271 B/op     0 allocs/op
Benchmark_Page_Render/Default-16       12933     93111 ns/op      0 B/op     0 allocs/op
Benchmark_Page_BuildRender/Default-16   6214    206834 ns/op    427 B/op     0 allocs/op

Parsing a ~30Kb page:

// Default                - 420 nodes
Benchmark_Parse_Page/...                52030   115220 ns/op  20755 B/op  1424 allocs/op

// ReuseBuffer            - 420 nodes
Benchmark_Parse_Page/...                81014    72750 ns/op    584 B/op     6 allocs/op

// Reuse + KeepEdge       - 420 nodes
Benchmark_Parse_Page/...                81722    71658 ns/op    583 B/op     6 allocs/op

// Reuse + KeepWhitespace - 800 nodes
Benchmark_Parse_Page/...                67941    88953 ns/op    604 B/op     6 allocs/op

// Reuse + Keep all       - 826 nodes
Benchmark_Parse_Page/...                65893    91337 ns/op    595 B/op     6 allocs/op

Contribution

Pull requests are welcome. For major changes, please open an issue first.

Documentation

Index

Constants

View Source
const (
	// RenderAssumeNoReplace skips duplicate checks for classes and attributes.
	// This may speed up rendering of big class/attribute lists.
	// In most cases this is not needed.
	RenderAssumeNoReplace = 1 << iota
)

Variables

View Source
var NoPool bool

NoPool disables automatic pooling.

View Source
var NoPoolCheck bool = false

NoPoolCheck disables pool corruption checks (CAS on Get/Release).

Functions

func UniqueID

func UniqueID() string

func ValidAttr

func ValidAttr(attr string) bool

func ValidClass

func ValidClass(class string) bool

func ValidTag

func ValidTag(tag string) bool

func WriteFloat

func WriteFloat(w io.Writer, f float64) error

func WriteInt

func WriteInt(w io.Writer, n int64) error

func WriteString

func WriteString(w io.Writer, s string) (int, error)

func WriteUint

func WriteUint(w io.Writer, n uint64) error

Types

type EscapeWriter

type EscapeWriter func(p []byte) (n int, err error)

EscapeWriter is an io.Writer that escapes HTML special characters.

func (EscapeWriter) Write

func (w EscapeWriter) Write(p []byte) (int, error)

type Mod

type Mod = func(n *Node)

Mod represents a function that modifies a Node.

func Accept

func Accept(v string) Mod

func AcceptCharset

func AcceptCharset(v string) Mod

func AccessKey

func AccessKey(v string) Mod

func Action

func Action(v string) Mod

func Allow

func Allow(v string) Mod

func AllowFullscreen

func AllowFullscreen(v ...TypedValue) Mod

func Alt

func Alt(v string) Mod

func Aria

func Aria(name string, v TypedValue) Mod

func As

func As(v string) Mod

func Async

func Async(v ...TypedValue) Mod

func Attr

func Attr(name string, value ...string) Mod

Attr returns a Mod that sets an attribute. If value is omitted, it sets a boolean attribute. Attr should not be used to set a class attribute; use Class instead.

func AttrBool

func AttrBool(name string, value ...bool) Mod

AttrBool returns a Mod that sets a boolean attribute. If value is omitted, it is treated as enabled.

func AttrValue

func AttrValue(name string, value ...TypedValue) Mod

AttrValue returns a Mod that sets an attribute. If value is omitted, it sets a boolean attribute. AttrValue should not be used to set a class attribute; use Class instead.

func Autocapitalize

func Autocapitalize(v string) Mod

func Autocomplete

func Autocomplete(v string) Mod

func Autofocus

func Autofocus(v ...TypedValue) Mod

func Autoplay

func Autoplay(v ...TypedValue) Mod

func Capture

func Capture(v string) Mod

func Charset

func Charset(v string) Mod

func Checked

func Checked(v ...TypedValue) Mod

func CiteAttr

func CiteAttr(v string) Mod

func Class

func Class(class string) Mod

Class returns a Mod that adds a class name to the node.

func ColSpan

func ColSpan(v int) Mod

func Content

func Content(nodes ...*Node) Mod

Content returns a Mod that sets (replaces) the content of the node.

func ContentAttr

func ContentAttr(v string) Mod

func Controls

func Controls(v ...TypedValue) Mod

func CrossOrigin

func CrossOrigin(v string) Mod

func Data

func Data(name string, v TypedValue) Mod

func DateTime

func DateTime(v string) Mod

func Decoding

func Decoding(v string) Mod

func Default

func Default(v ...TypedValue) Mod

func Defer

func Defer(v ...TypedValue) Mod

func Dir

func Dir(v string) Mod

func Disabled

func Disabled(v ...TypedValue) Mod

func Download

func Download(value ...string) Mod

Download sets the "download" attribute, If value is omitted, it sets a boolean attribute.

func Draggable

func Draggable(v ...bool) Mod

Draggable sets the "draggable". If value is omitted, it sets a string value "true". If value is provided and false, it sets a string value "false".

func EnterKeyHint

func EnterKeyHint(v string) Mod

func For

func For(v string) Mod

func FormNoValidate

func FormNoValidate(v ...TypedValue) Mod

func GroupLabel

func GroupLabel(v string) Mod

func Headers

func Headers(v string) Mod

func Height

func Height(v int) Mod

func Hint

func Hint(v string) Mod

func Href

func Href(v string) Mod

func Hreflang

func Hreflang(v string) Mod

func HttpEquiv

func HttpEquiv(v string) Mod

func ID

func ID(v string) Mod

func Inert

func Inert(v ...TypedValue) Mod

func InputMode

func InputMode(v string) Mod

func IsMap

func IsMap(v ...TypedValue) Mod

func ItemScope

func ItemScope(v ...TypedValue) Mod

func Kind

func Kind(v string) Mod

func Lang

func Lang(v string) Mod

func List

func List(v string) Mod

func Loading

func Loading(v string) Mod

func Loop

func Loop(v ...TypedValue) Mod

func Max

func Max(v int) Mod

func MaxDate

func MaxDate(v time.Time) Mod

func Min

func Min(v int) Mod

func MinDate

func MinDate(v time.Time) Mod

func ModIf

func ModIf(cond bool, fn func() Mod) Mod

ModIf conditionally returns a modifier produced by fn when cond is true. If cond is false, ModIf returns nil.

func Mods

func Mods(mods ...Mod) Mod

Mods combines multiple modifiers into a single Mod.

func Multiple

func Multiple(v ...TypedValue) Mod

func Muted

func Muted(v ...TypedValue) Mod

func Name

func Name(v string) Mod

func NoModule

func NoModule(v ...TypedValue) Mod

func Novalidate

func Novalidate(v ...TypedValue) Mod

func On

func On(event string, js string) Mod

func OnBlur

func OnBlur(js string) Mod

func OnChange

func OnChange(js string) Mod

func OnClick

func OnClick(js string) Mod

func OnCopy

func OnCopy(js string) Mod

func OnCut

func OnCut(js string) Mod

func OnDblClick

func OnDblClick(js string) Mod

func OnDrag

func OnDrag(js string) Mod

func OnDragEnd

func OnDragEnd(js string) Mod

func OnDragEnter

func OnDragEnter(js string) Mod

func OnDragLeave

func OnDragLeave(js string) Mod

func OnDragOver

func OnDragOver(js string) Mod

func OnDragStart

func OnDragStart(js string) Mod

func OnDrop

func OnDrop(js string) Mod

func OnError

func OnError(js string) Mod

func OnFocus

func OnFocus(js string) Mod

func OnInput

func OnInput(js string) Mod

func OnKeyDown

func OnKeyDown(js string) Mod

func OnKeyPress

func OnKeyPress(js string) Mod

func OnKeyUp

func OnKeyUp(js string) Mod

func OnLoad

func OnLoad(js string) Mod

func OnMouseDown

func OnMouseDown(js string) Mod

func OnMouseEnter

func OnMouseEnter(js string) Mod

func OnMouseLeave

func OnMouseLeave(js string) Mod

func OnMouseMove

func OnMouseMove(js string) Mod

func OnMouseOut

func OnMouseOut(js string) Mod

func OnMouseOver

func OnMouseOver(js string) Mod

func OnMouseUp

func OnMouseUp(js string) Mod

func OnPaste

func OnPaste(js string) Mod

func OnReset

func OnReset(js string) Mod

func OnScroll

func OnScroll(js string) Mod

func OnSelect

func OnSelect(js string) Mod

func OnSubmit

func OnSubmit(js string) Mod

func OnWheel

func OnWheel(js string) Mod

func Open

func Open(v ...TypedValue) Mod

func Optimum

func Optimum(v float64) Mod

func Pattern

func Pattern(v string) Mod

func Ping

func Ping(v string) Mod

func Placeholder

func Placeholder(v string) Mod

func PlaysInline

func PlaysInline(v ...TypedValue) Mod

func Poster

func Poster(v string) Mod

func Postpone added in v0.3.1

func Postpone(mods ...Mod) Mod

Postpone adds mods to be applied just before rendering.

func Preload

func Preload(v string) Mod

func Readonly

func Readonly(v ...TypedValue) Mod

func ReferrerPolicy

func ReferrerPolicy(v string) Mod

func Rel

func Rel(v string) Mod

func Required

func Required(v ...TypedValue) Mod

func Reversed

func Reversed(v ...TypedValue) Mod

func Role

func Role(v string) Mod

func RowSpan

func RowSpan(v int) Mod

func Selected

func Selected(v ...TypedValue) Mod

func Sizes

func Sizes(v string) Mod

func Slot

func Slot(name string, nodes ...*Node) Mod

Slot returns a Mod that sets the content of a named slot. If the slot exists, its content is replaced.

func SlotAttr

func SlotAttr(v string) Mod

func Spellcheck

func Spellcheck(v ...bool) Mod

Spellcheck sets the "spellcheck" attribute. If value is omitted, it sets a boolean attribute. If value is provided and false, it sets a string value "false".

func Src

func Src(v string) Mod

func Srcdoc

func Srcdoc(v string) Mod

func Srclang

func Srclang(v string) Mod

func Srcset

func Srcset(v string) Mod

func Start

func Start(v int) Mod

func Step

func Step(value ...int) Mod

Step adds a "step" attribute. If value is omitted, "any" is used.

func Style

func Style(v string) Mod

func TabIndex

func TabIndex(v int) Mod

func Tag

func Tag(tag string) Mod

Tag returns a Mod that sets the HTML tag name.

func TagEx

func TagEx(tag string, void bool) Mod

TagEx returns a Mod that sets the HTML tag name and void status.

func TextContent

func TextContent(s string) Mod

TextContent returns a Mod that sets (replaces) the content of the node to a single text node. The content is HTML-escaped during rendering.

func Translate

func Translate(v string) Mod

func Type

func Type(v string) Mod

func Value

func Value(v TypedValue) Mod

func Var

func Var(name string, value string) Mod

Var returns a Mod that attaches arbitrary user data (variable) to the node. These variables are not rendered to HTML.

func VarValue

func VarValue(name string, value TypedValue) Mod

VarValue returns a Mod that attaches arbitrary user data (variable) to the node. These variables are not rendered to HTML.

func Viewport

func Viewport(v string) Mod

func Width

func Width(v int) Mod

func Wrap

func Wrap(v string) Mod

func WriteFn

func WriteFn(fn func(*Node, io.Writer) error) Mod

WriteFn returns a Mod that overrides the default rendering logic with fn.

type Node

type Node struct {
	// contains filtered or unexported fields
}

Node represents an HTML element or a special rendering node (e.g. text/raw/group).

func A

func A(m ...Mod) *Node

func Abbr

func Abbr(m ...Mod) *Node

func Address

func Address(m ...Mod) *Node

func Area

func Area(m ...Mod) *Node

func Article

func Article(m ...Mod) *Node

func Aside

func Aside(m ...Mod) *Node

func Audio

func Audio(m ...Mod) *Node

func B

func B(m ...Mod) *Node

func Base

func Base(m ...Mod) *Node

func Bdi

func Bdi(m ...Mod) *Node

func Bdo

func Bdo(m ...Mod) *Node

func Blockquote

func Blockquote(m ...Mod) *Node

func Body

func Body(m ...Mod) *Node

func Br

func Br(m ...Mod) *Node

func Build

func Build(tag string, mods ...Mod) *Node

Build retrieves a Node from the pool, sets its tag, and applies the provided modifiers.

func Button

func Button(m ...Mod) *Node

func Canvas

func Canvas(m ...Mod) *Node

func Caption

func Caption(m ...Mod) *Node

func Cite

func Cite(m ...Mod) *Node

func Code

func Code(m ...Mod) *Node

func Col

func Col(m ...Mod) *Node

func Colgroup

func Colgroup(m ...Mod) *Node

func DOCTYPE

func DOCTYPE() *Node

func DataTag

func DataTag(v string, mods ...Mod) *Node

func Datalist

func Datalist(m ...Mod) *Node

func Dd

func Dd(m ...Mod) *Node

func Del

func Del(m ...Mod) *Node

func Details

func Details(m ...Mod) *Node

func Dfn

func Dfn(m ...Mod) *Node

func Dialog

func Dialog(m ...Mod) *Node

func Div

func Div(m ...Mod) *Node

func Dl

func Dl(m ...Mod) *Node

func Dt

func Dt(m ...Mod) *Node

func Em

func Em(m ...Mod) *Node

func Embed

func Embed(m ...Mod) *Node

func Fieldset

func Fieldset(m ...Mod) *Node

func Figcaption

func Figcaption(m ...Mod) *Node

func Figure

func Figure(m ...Mod) *Node
func Footer(m ...Mod) *Node

func Form

func Form(m ...Mod) *Node

func Get

func Get() *Node

Get retrieves a zeroed Node from the global pool. Most users should use Build, Group, Text and others instead.

func Group

func Group(nodes ...*Node) *Node

Group creates a logical group of nodes that renders its children without a wrapping parent tag.

func H1

func H1(m ...Mod) *Node

func H2

func H2(m ...Mod) *Node

func H3

func H3(m ...Mod) *Node

func H4

func H4(m ...Mod) *Node

func H5

func H5(m ...Mod) *Node

func H6

func H6(m ...Mod) *Node
func Head(m ...Mod) *Node
func Header(m ...Mod) *Node

func Hr

func Hr(m ...Mod) *Node

func Html

func Html(m ...Mod) *Node

func I

func I(m ...Mod) *Node

func Icon

func Icon(href string, mods ...Mod) *Node

func If

func If(cond bool, fn func() *Node) *Node

If conditionally returns a node produced by fn when cond is true. If cond is false, If returns nil.

func Iframe

func Iframe(m ...Mod) *Node

func Img

func Img(m ...Mod) *Node

func Input

func Input(m ...Mod) *Node

func Ins

func Ins(m ...Mod) *Node

func Join added in v0.4.0

func Join(nodes ...*Node) *Node

Join returns a Group if at least one of the provided nodes is not nil. Otherwise, it returns nil.

func Kbd

func Kbd(m ...Mod) *Node

func Label

func Label(m ...Mod) *Node

func Legend

func Legend(m ...Mod) *Node

func Li

func Li(m ...Mod) *Node
func Link(m ...Mod) *Node

func Main

func Main(m ...Mod) *Node

func Map

func Map(m ...Mod) *Node

func Mark

func Mark(m ...Mod) *Node

func Meta

func Meta(m ...Mod) *Node

func Meter

func Meter(m ...Mod) *Node
func Nav(m ...Mod) *Node

func Noscript

func Noscript(m ...Mod) *Node

func Object

func Object(m ...Mod) *Node

func Ol

func Ol(m ...Mod) *Node

func Optgroup

func Optgroup(m ...Mod) *Node

func Option

func Option(m ...Mod) *Node

func Output

func Output(m ...Mod) *Node

func P

func P(m ...Mod) *Node

func Param

func Param(m ...Mod) *Node

func Parse added in v0.5.0

func Parse(data []byte, flags ...ParseFlag) (*Node, error)

Parse builds Node tree from HTML bytes.

For multiple top-level nodes, Parse returns a Group node.

func Picture

func Picture(m ...Mod) *Node

func Pre

func Pre(m ...Mod) *Node

func Progress

func Progress(m ...Mod) *Node

func Q

func Q(m ...Mod) *Node

func RawBytes

func RawBytes(b []byte) *Node

RawBytes creates a raw HTML node from a byte slice. The content is written directly to the output without escaping.

func RawString

func RawString(s string) *Node

RawString creates a raw HTML node from a string. The content is written directly to the output without escaping.

func Rp

func Rp(m ...Mod) *Node

func Rt

func Rt(m ...Mod) *Node

func Ruby

func Ruby(m ...Mod) *Node

func S

func S(m ...Mod) *Node

func Samp

func Samp(m ...Mod) *Node

func Script

func Script(m ...Mod) *Node

func Section

func Section(m ...Mod) *Node

func Select

func Select(m ...Mod) *Node

func SlotTag

func SlotTag(name string, m ...Mod) *Node

func Small

func Small(m ...Mod) *Node

func Source

func Source(m ...Mod) *Node

func Span

func Span(m ...Mod) *Node

func Static

func Static(fn func() *Node) *Node

Static renders the node returned by fn once and caches the result globally. Subsequent calls return a cached raw byte node, avoiding re-rendering.

The cache key is the function pointer; closures are cached by function address and therefore execute at most once, regardless of captured variables.

func Strong

func Strong(m ...Mod) *Node

func StyleTag

func StyleTag(m ...Mod) *Node

func Stylesheet

func Stylesheet(href string, mods ...Mod) *Node

func Sub

func Sub(m ...Mod) *Node

func Summary

func Summary(m ...Mod) *Node

func Sup

func Sup(m ...Mod) *Node

func Table

func Table(m ...Mod) *Node

func Tbody

func Tbody(m ...Mod) *Node

func Td

func Td(m ...Mod) *Node

func Template

func Template(m ...Mod) *Node

func Text

func Text(s string) *Node

Text creates a text node from a string. The content is HTML-escaped during rendering.

func TextValue

func TextValue(v TypedValue) *Node

TextValue creates a text node from an arbitrary value. The content is HTML-escaped during rendering.

func Textarea

func Textarea(m ...Mod) *Node

func Tfoot

func Tfoot(m ...Mod) *Node

func Th

func Th(m ...Mod) *Node

func Thead

func Thead(m ...Mod) *Node

func Time

func Time(m ...Mod) *Node

func Title

func Title(value string, mods ...Mod) *Node

func TitleValue

func TitleValue(value TypedValue, mods ...Mod) *Node

func Tr

func Tr(m ...Mod) *Node

func Track

func Track(m ...Mod) *Node

func U

func U(m ...Mod) *Node

func Ul

func Ul(m ...Mod) *Node

func VarTag

func VarTag(value string, mods ...Mod) *Node

func Video

func Video(m ...Mod) *Node

func Wbr

func Wbr(m ...Mod) *Node

func (*Node) A added in v0.3.0

func (n *Node) A(name string, value ...string) *Node

A is an alias for Attr

func (*Node) AV added in v0.3.0

func (n *Node) AV(name string, value ...TypedValue) *Node

AV is an alias for AttrValue

func (*Node) Accept

func (n *Node) Accept(v string) *Node

func (*Node) AcceptCharset

func (n *Node) AcceptCharset(v string) *Node

func (*Node) AccessKey

func (n *Node) AccessKey(v string) *Node

func (*Node) Action

func (n *Node) Action(v string) *Node

func (*Node) All added in v0.3.0

func (n *Node) All() iter.Seq[*Node]

All returns an iterator over node's contents.

func (*Node) Allow

func (n *Node) Allow(v string) *Node

func (*Node) AllowFullscreen

func (n *Node) AllowFullscreen(v ...TypedValue) *Node

func (*Node) Alt

func (n *Node) Alt(v string) *Node

func (*Node) Append

func (n *Node) Append(nodes ...*Node) *Node

Append adds nodes to the end of the content.

func (*Node) AppendSeq added in v0.5.0

func (n *Node) AppendSeq(iter iter.Seq[*Node]) *Node

AppendSeq adds nodes provided by the iterator to the end of content.

func (*Node) AppendSlot

func (n *Node) AppendSlot(name string, nodes ...*Node) *Node

AppendSlot adds nodes to the end of a named slot.

func (*Node) AppendSlotSeq added in v0.5.0

func (n *Node) AppendSlotSeq(name string, seq iter.Seq[*Node]) *Node

AppendSlotSeq adds nodes to the end of a named slot.

func (*Node) Apply

func (n *Node) Apply(mods []Mod) *Node

Apply applies a slice of modifiers to the node.

func (*Node) Aria

func (n *Node) Aria(name string, v TypedValue) *Node

func (*Node) As

func (n *Node) As(v string) *Node

func (*Node) Async

func (n *Node) Async(v ...TypedValue) *Node

func (*Node) Attr

func (n *Node) Attr(name string, value ...string) *Node

Attr sets the value of an attribute. If value is omitted, it sets a boolean attribute. To unset a boolean attribute, use BoolAttr(name, false) or RemoveAttr(name) or AttrValue(name, Unset). Attr should not be used to set a class attribute; use Class instead.

func (*Node) AttrBool

func (n *Node) AttrBool(name string, value ...bool) *Node

AttrBool sets the value of an attribute. If value is omitted, it is treated as enabled. To unset a boolean attribute, use BoolAttr(name, false) or RemoveAttr(name) or AttrValue(name, Unset).

func (*Node) AttrValue

func (n *Node) AttrValue(name string, value ...TypedValue) *Node

AttrValue sets the value of an attribute. If value is omitted, it sets a boolean attribute. To unset a boolean attribute, use AttrValue(name, Unset) or RemoveAttr(name). AttrValue should not be used to set a class attribute; use Class instead.

func (*Node) Attrs added in v0.3.0

func (n *Node) Attrs() iter.Seq2[string, TypedValue]

Attrs returns an iterator over active attributes.

func (*Node) Autocapitalize

func (n *Node) Autocapitalize(v string) *Node

func (*Node) Autocomplete

func (n *Node) Autocomplete(v string) *Node

func (*Node) Autofocus

func (n *Node) Autofocus(v ...TypedValue) *Node

func (*Node) Autoplay

func (n *Node) Autoplay(v ...TypedValue) *Node

func (*Node) C added in v0.3.0

func (n *Node) C(name string) *Node

C is an alias for Class.

func (*Node) Capture

func (n *Node) Capture(v string) *Node

func (*Node) Charset

func (n *Node) Charset(v string) *Node

func (*Node) Checked

func (n *Node) Checked(v ...TypedValue) *Node

func (*Node) Cite

func (n *Node) Cite(v string) *Node

func (*Node) Class

func (n *Node) Class(name string) *Node

Class adds a class name to the node. Multiple classes can be separated by spaces.

func (*Node) Classes added in v0.3.0

func (n *Node) Classes() iter.Seq[string]

Classes returns iterator over active classes.

func (*Node) Clear added in v0.3.0

func (n *Node) Clear()

Clear clears node attributes, classes and contents. All children are returned to the pool unless pooling is disabled. Raw and Text nodes are unaffected by Clear.

func (*Node) Clone added in v0.5.0

func (n *Node) Clone() *Node

Clone creates a deep copy of n and all nested content/slot trees. The clone is acquired from the pool, reuses internal buffers and does not copy pooling links. Pool ownership flag is not copied so the clone can be safely released.

func (*Node) ColSpan

func (n *Node) ColSpan(v int) *Node

func (*Node) Content

func (n *Node) Content(nodes ...*Node) *Node

Content sets (replaces) the content of the node with the provided nodes.

func (*Node) ContentAttr

func (n *Node) ContentAttr(v string) *Node

func (*Node) ContentSeq added in v0.5.0

func (n *Node) ContentSeq(iter iter.Seq[*Node]) *Node

ContentSeq sets (replaces) the content with nodes provided by the iterator.

func (*Node) Controls

func (n *Node) Controls(v ...TypedValue) *Node

func (*Node) CopyClassPrefix

func (n *Node) CopyClassPrefix(prefixes ...string) Mod

CopyClassPrefix returns a Mod that copies classes with specific prefixes to a destination node.

func (*Node) CopyClassPrefixTo

func (n *Node) CopyClassPrefixTo(dst *Node, prefixes ...string) *Node

CopyClassPrefixTo copies classes starting with the given prefixes to the destination node.

func (*Node) CopyClassSuffix

func (n *Node) CopyClassSuffix(suffixes ...string) Mod

CopyClassSuffix returns a Mod that copies classes with specific suffixes to a destination node.

func (*Node) CopyClassSuffixTo

func (n *Node) CopyClassSuffixTo(dst *Node, suffixes ...string) *Node

CopyClassSuffixTo copies classes ending with the given suffixes to the destination node.

func (*Node) Count added in v0.2.0

func (n *Node) Count() int

Count returns the total number of nodes in the tree.

func (*Node) CrossOrigin

func (n *Node) CrossOrigin(v string) *Node

func (*Node) Data

func (n *Node) Data(name string, v TypedValue) *Node

func (*Node) DateTime

func (n *Node) DateTime(v string) *Node

func (*Node) Decoding

func (n *Node) Decoding(v string) *Node

func (*Node) Default

func (n *Node) Default(v ...TypedValue) *Node

func (*Node) DefaultContent added in v0.2.0

func (n *Node) DefaultContent(fn func(*Node)) *Node

DefaultContent postpones a function that executes fn if the node's content is empty.

func (*Node) Defer

func (n *Node) Defer(v ...TypedValue) *Node

func (*Node) DeleteSlot

func (n *Node) DeleteSlot(names ...string) *Node

DeleteSlot removes specific named slots and releases their content.

func (*Node) Dir

func (n *Node) Dir(v string) *Node

func (*Node) Disabled

func (n *Node) Disabled(v ...TypedValue) *Node

func (*Node) Download

func (n *Node) Download(value ...string) *Node

Download sets the "download" attribute, If value is omitted, it sets a boolean attribute.

func (*Node) Draggable

func (n *Node) Draggable(v ...bool) *Node

Draggable sets the "draggable". If value is omitted, it sets a string value "true". If value is provided and false, it sets a string value "false".

func (*Node) Each added in v0.3.0

func (n *Node) Each(fn func(*Node) bool) *Node

Each calls fn for each non-nil child node. Iteration stops if fn returns false.

func (*Node) EachAttr

func (n *Node) EachAttr(fn func(string, TypedValue) bool) *Node

EachAttr iterates over all attributes, calling fn for each. Iteration stops if fn returns false.

func (*Node) EachClass

func (n *Node) EachClass(fn func(string) bool) *Node

EachClass iterates over all active classes, calling fn for each. Iteration stops if fn returns false.

func (*Node) EachVar added in v0.4.0

func (n *Node) EachVar(fn func(string, TypedValue) bool)

EachVar iterates over all active classes, calling fn for each. Iteration stops if fn returns false.

func (*Node) EnterKeyHint

func (n *Node) EnterKeyHint(v string) *Node

func (*Node) ExtractContent

func (n *Node) ExtractContent() *Node

ExtractContent removes and returns the content of the node as Group node.

func (*Node) ExtractContentNodes added in v0.2.0

func (n *Node) ExtractContentNodes() (extracted []*Node)

ExtractContentNodes removes and returns the content of the node.

func (*Node) ExtractSlot

func (n *Node) ExtractSlot(name string) *Node

ExtractSlot removes and returns the contents of a named slot as a Group node. If slot does not exist or has no content, ExtractSlot returns nil.

func (*Node) ExtractSlotNodes added in v0.2.0

func (n *Node) ExtractSlotNodes(name string) []*Node

ExtractSlotNodes removes and returns the content of a named slot.

func (*Node) For

func (n *Node) For(v string) *Node

func (*Node) FormNoValidate

func (n *Node) FormNoValidate(v ...TypedValue) *Node

func (*Node) GetAttr

func (n *Node) GetAttr(name string) TypedValue

GetAttr retrieves the attribute value by name. Returns a zero value if not found. Use TypedValue.Valid to check for validity.

func (*Node) GetTag

func (n *Node) GetTag() (string, bool)

GetTag returns the current tag name and whether it is a void (self-closing) element.

func (*Node) GetVar

func (n *Node) GetVar(name string) TypedValue

GetVar retrieves the value of a user variable by name. Returns unset value if not found.

func (*Node) GroupLabel

func (n *Node) GroupLabel(v string) *Node

func (*Node) HasAttr

func (n *Node) HasAttr(names ...string) bool

HasAttr checks if the node has at least one of the specified attributes.

func (*Node) HasAttrAll

func (n *Node) HasAttrAll(names ...string) bool

HasAttrAll checks if the node has all of the specified attributes.

func (*Node) HasAttrPrefix

func (n *Node) HasAttrPrefix(prefix string) bool

HasAttrPrefix checks if the node has any attribute starting with the given prefix.

func (*Node) HasAttrSuffix

func (n *Node) HasAttrSuffix(suffix string) bool

HasAttrSuffix checks if the node has any attribute ending with the given suffix.

func (*Node) HasClass

func (n *Node) HasClass(names ...string) bool

HasClass checks if the node has at least one of the specified classes.

func (*Node) HasClassAll

func (n *Node) HasClassAll(names ...string) bool

HasClassAll checks if the node has all of the specified classes.

func (*Node) HasClassPrefix

func (n *Node) HasClassPrefix(prefix string) bool

HasClassPrefix checks if the node has any class starting with the given prefix.

func (*Node) HasClassSuffix

func (n *Node) HasClassSuffix(suffix string) bool

HasClassSuffix checks if the node has any class ending with the given suffix.

func (*Node) HasContent

func (n *Node) HasContent() bool

HasContent checks if the node has any content.

func (*Node) HasSlot

func (n *Node) HasSlot(name string) bool

HasSlot checks if a named slot exists and has content.

func (*Node) HasVar

func (n *Node) HasVar(names ...string) bool

HasVar checks if the node has at least one of the specified variables.

func (*Node) HasVarAll

func (n *Node) HasVarAll(names ...string) bool

HasVarAll checks if the node has all the specified variables.

func (*Node) Headers

func (n *Node) Headers(v string) *Node

func (*Node) Height

func (n *Node) Height(v int) *Node

func (*Node) Hint

func (n *Node) Hint(v string) *Node

func (*Node) Href

func (n *Node) Href(v string) *Node

func (*Node) Hreflang

func (n *Node) Hreflang(v string) *Node

func (*Node) HttpEquiv

func (n *Node) HttpEquiv(v string) *Node

func (*Node) ID

func (n *Node) ID(v string) *Node

func (*Node) If

func (n *Node) If(cond bool, fn func(*Node)) *Node

If executes fn on the node if cond is true.

func (*Node) Inert

func (n *Node) Inert(v ...TypedValue) *Node

func (*Node) InputMode

func (n *Node) InputMode(v string) *Node

func (*Node) IsMap

func (n *Node) IsMap(v ...TypedValue) *Node

func (*Node) ItemScope

func (n *Node) ItemScope(v ...TypedValue) *Node

func (*Node) Kind

func (n *Node) Kind(v string) *Node

func (*Node) Lang

func (n *Node) Lang(v string) *Node

func (*Node) Len added in v0.5.0

func (n *Node) Len() int

Len returns the number of content nodes.

func (*Node) List

func (n *Node) List(v string) *Node

func (*Node) Loading

func (n *Node) Loading(v string) *Node

func (*Node) Loop

func (n *Node) Loop(v ...TypedValue) *Node

func (*Node) Max

func (n *Node) Max(v int) *Node

func (*Node) MaxDate

func (n *Node) MaxDate(v time.Time) *Node

func (*Node) Min

func (n *Node) Min(v int) *Node

func (*Node) MinDate

func (n *Node) MinDate(v time.Time) *Node

func (*Node) Mod

func (n *Node) Mod(mods ...Mod) *Node

Mod applies the provided modifiers to the node.

func (*Node) ModIf

func (n *Node) ModIf(cond bool, fn func(*Node) Mod) Mod

ModIf executes fn and returns the resulting Mod if cond is true.

func (*Node) MoveAttr

func (n *Node) MoveAttr(names ...string) Mod

MoveAttr returns a Mod that moves specific attributes to a destination node.

func (*Node) MoveAttrPrefix

func (n *Node) MoveAttrPrefix(prefix string) Mod

MoveAttrPrefix returns a Mod that moves attributes with a specific prefix to a destination node.

func (*Node) MoveAttrPrefixTo

func (n *Node) MoveAttrPrefixTo(dst *Node, prefix string) *Node

MoveAttrPrefixTo moves all attributes starting with the given prefix to the destination node.

func (*Node) MoveAttrSuffix

func (n *Node) MoveAttrSuffix(suffix string) Mod

MoveAttrSuffix returns a Mod that moves attributes with a specific suffix to a destination node.

func (*Node) MoveAttrSuffixTo

func (n *Node) MoveAttrSuffixTo(dst *Node, suffix string) *Node

MoveAttrSuffixTo moves all attributes ending with the given suffix to the destination node.

func (*Node) MoveAttrTo

func (n *Node) MoveAttrTo(dst *Node, names ...string) *Node

MoveAttrTo moves specific attributes from the current node to the destination node.

func (*Node) MoveClass

func (n *Node) MoveClass(names ...string) Mod

MoveClass returns a Mod that moves specific classes to a destination node.

func (*Node) MoveClassPrefix

func (n *Node) MoveClassPrefix(prefixes ...string) Mod

MoveClassPrefix returns a Mod that moves classes with specific prefixes to a destination node.

func (*Node) MoveClassPrefixTo

func (n *Node) MoveClassPrefixTo(dst *Node, prefixes ...string) *Node

MoveClassPrefixTo moves classes starting with the given prefixes to the destination node.

func (*Node) MoveClassSuffix

func (n *Node) MoveClassSuffix(suffixes ...string) Mod

MoveClassSuffix returns a Mod that moves classes with specific suffixes to a destination node.

func (*Node) MoveClassSuffixTo

func (n *Node) MoveClassSuffixTo(dst *Node, suffixes ...string) *Node

MoveClassSuffixTo moves classes ending with the given suffixes to the destination node.

func (*Node) MoveClassTo

func (n *Node) MoveClassTo(dst *Node, names ...string) *Node

MoveClassTo moves specific classes from the current node to the destination node.

func (*Node) MoveContent

func (n *Node) MoveContent(dst *Node)

MoveContent is a Mod that moves the content to a destination node.

func (*Node) MoveContentTo

func (n *Node) MoveContentTo(dst *Node) *Node

MoveContentTo moves all content from the current node to the destination node.

func (*Node) MoveSlot

func (n *Node) MoveSlot(names ...string) Mod

MoveSlot returns a Mod that moves named slots to a destination node.

func (*Node) MoveSlotTo

func (n *Node) MoveSlotTo(dst *Node, names ...string) *Node

MoveSlotTo moves named slots and their content to the destination node.

func (*Node) MoveVarPrefixTo

func (n *Node) MoveVarPrefixTo(dst *Node, prefix string) *Node

MoveVarPrefixTo moves variables starting with the given prefix to the destination node.

func (*Node) MoveVarSuffixTo

func (n *Node) MoveVarSuffixTo(dst *Node, prefix string) *Node

MoveVarSuffixTo moves variables ending with the given suffix to the destination node.

func (*Node) MoveVarTo

func (n *Node) MoveVarTo(dst *Node, names ...string) *Node

MoveVarTo moves specific variables from the current node to the destination node.

func (*Node) Multiple

func (n *Node) Multiple(v ...TypedValue) *Node

func (*Node) Muted

func (n *Node) Muted(v ...TypedValue) *Node

func (*Node) Name

func (n *Node) Name(v string) *Node

func (*Node) NoContent added in v0.2.0

func (n *Node) NoContent() bool

NoContent checks if the node has no content.

func (*Node) NoModule

func (n *Node) NoModule(v ...TypedValue) *Node

func (*Node) Novalidate

func (n *Node) Novalidate(v ...TypedValue) *Node

func (*Node) On

func (n *Node) On(event string, js string) *Node

func (*Node) OnBlur

func (n *Node) OnBlur(js string) *Node

func (*Node) OnChange

func (n *Node) OnChange(js string) *Node

func (*Node) OnClick

func (n *Node) OnClick(js string) *Node

func (*Node) OnCopy

func (n *Node) OnCopy(js string) *Node

func (*Node) OnCut

func (n *Node) OnCut(js string) *Node

func (*Node) OnDblClick

func (n *Node) OnDblClick(js string) *Node

func (*Node) OnDrag

func (n *Node) OnDrag(js string) *Node

func (*Node) OnDragEnd

func (n *Node) OnDragEnd(js string) *Node

func (*Node) OnDragEnter

func (n *Node) OnDragEnter(js string) *Node

func (*Node) OnDragLeave

func (n *Node) OnDragLeave(js string) *Node

func (*Node) OnDragOver

func (n *Node) OnDragOver(js string) *Node

func (*Node) OnDragStart

func (n *Node) OnDragStart(js string) *Node

func (*Node) OnDrop

func (n *Node) OnDrop(js string) *Node

func (*Node) OnError

func (n *Node) OnError(js string) *Node

func (*Node) OnFocus

func (n *Node) OnFocus(js string) *Node

func (*Node) OnInput

func (n *Node) OnInput(js string) *Node

func (*Node) OnKeyDown

func (n *Node) OnKeyDown(js string) *Node

func (*Node) OnKeyPress

func (n *Node) OnKeyPress(js string) *Node

func (*Node) OnKeyUp

func (n *Node) OnKeyUp(js string) *Node

func (*Node) OnLoad

func (n *Node) OnLoad(js string) *Node

func (*Node) OnMouseDown

func (n *Node) OnMouseDown(js string) *Node

func (*Node) OnMouseEnter

func (n *Node) OnMouseEnter(js string) *Node

func (*Node) OnMouseLeave

func (n *Node) OnMouseLeave(js string) *Node

func (*Node) OnMouseMove

func (n *Node) OnMouseMove(js string) *Node

func (*Node) OnMouseOut

func (n *Node) OnMouseOut(js string) *Node

func (*Node) OnMouseOver

func (n *Node) OnMouseOver(js string) *Node

func (*Node) OnMouseUp

func (n *Node) OnMouseUp(js string) *Node

func (*Node) OnPaste

func (n *Node) OnPaste(js string) *Node

func (*Node) OnReset

func (n *Node) OnReset(js string) *Node

func (*Node) OnScroll

func (n *Node) OnScroll(js string) *Node

func (*Node) OnSelect

func (n *Node) OnSelect(js string) *Node

func (*Node) OnSubmit

func (n *Node) OnSubmit(js string) *Node

func (*Node) OnWheel

func (n *Node) OnWheel(js string) *Node

func (*Node) Open

func (n *Node) Open(v ...TypedValue) *Node

func (*Node) Optimum

func (n *Node) Optimum(v float64) *Node

func (*Node) Own

func (n *Node) Own() *Node

Own marks the node as owned, preventing it from being returned to the pool by Release.

func (*Node) Owned

func (n *Node) Owned() bool

Owned returns true if the node has been marked as owned and will not be returned to the pool.

func (*Node) Pattern

func (n *Node) Pattern(v string) *Node

func (*Node) Ping

func (n *Node) Ping(v string) *Node

func (*Node) Placeholder

func (n *Node) Placeholder(v string) *Node

func (*Node) PlaysInline

func (n *Node) PlaysInline(v ...TypedValue) *Node

func (*Node) Poster

func (n *Node) Poster(v string) *Node

func (*Node) Postpone

func (n *Node) Postpone(mods ...Mod) *Node

Postpone adds mods to be applied just before rendering.

func (*Node) Preload

func (n *Node) Preload(v string) *Node

func (*Node) Prepend

func (n *Node) Prepend(nodes ...*Node) *Node

Prepend adds nodes to the beginning of the content.

func (*Node) PrependSeq added in v0.5.0

func (n *Node) PrependSeq(iter iter.Seq[*Node]) *Node

PrependSeq adds nodes provided by the iterator to the beginning of content.

func (*Node) PrependSlot

func (n *Node) PrependSlot(name string, nodes ...*Node) *Node

PrependSlot adds nodes to the beginning of a named slot.

func (*Node) PrependSlotSeq added in v0.5.0

func (n *Node) PrependSlotSeq(name string, seq iter.Seq[*Node]) *Node

PrependSlotSeq adds nodes to the beginning of a named slot.

func (*Node) Readonly

func (n *Node) Readonly(v ...TypedValue) *Node

func (*Node) ReferrerPolicy

func (n *Node) ReferrerPolicy(v string) *Node

func (*Node) Rel

func (n *Node) Rel(v string) *Node

func (*Node) Release

func (n *Node) Release()

Release returns the node and its children to the pool for reuse. If the node is marked as Owned or pooling is disabled, Release is no-op.

func (*Node) RemoveAttr

func (n *Node) RemoveAttr(names ...string) *Node

RemoveAttr removes the specified attributes from the node.

func (*Node) RemoveClass

func (n *Node) RemoveClass(names ...string) *Node

RemoveClass removes the specified class names from the node.

func (*Node) RemoveContent

func (n *Node) RemoveContent() *Node

RemoveContent clears the content and recursively releases all child nodes.

func (*Node) RemoveVar

func (n *Node) RemoveVar(names ...string) *Node

RemoveVar removes the specified variables from the node.

func (*Node) Render

func (n *Node) Render(w io.Writer, flags ...int) error

Render writes the HTML representation of the node to w. Optional flags alter the rendering behavior.

func (*Node) Required

func (n *Node) Required(v ...TypedValue) *Node

func (*Node) Reset added in v0.5.0

func (n *Node) Reset()

Reset completely resets the node. All children are returned to the pool unless pooling is disabled. Owned flag remains unchanged.

func (*Node) Reversed

func (n *Node) Reversed(v ...TypedValue) *Node

func (*Node) Role

func (n *Node) Role(v string) *Node

func (*Node) RowSpan

func (n *Node) RowSpan(v int) *Node

func (*Node) Selected

func (n *Node) Selected(v ...TypedValue) *Node

func (*Node) SetPoolingNeighbor

func (n *Node) SetPoolingNeighbor(x *Node)

SetPoolingNeighbor links another node to be released together with n.

func (*Node) SetTag

func (n *Node) SetTag(tag string) *Node

SetTag sets the HTML tag name of the node.

func (*Node) SetTagEx

func (n *Node) SetTagEx(tag string, void bool) *Node

SetTagEx sets the HTML tag name and explicitly controls the void element status.

func (*Node) SetWriteFn

func (n *Node) SetWriteFn(fn func(*Node, io.Writer) error) *Node

SetWriteFn overrides the default rendering logic of the node with fn.

func (*Node) Sizes

func (n *Node) Sizes(v string) *Node

func (*Node) Slot

func (n *Node) Slot(name string, nodes ...*Node) *Node

Slot sets (replaces) the content of a named slot. If the slot exists, its content is replaced.

func (*Node) SlotAttr

func (n *Node) SlotAttr(v string) *Node

func (*Node) SlotSeq added in v0.5.0

func (n *Node) SlotSeq(name string, iter iter.Seq[*Node]) *Node

SlotSeq sets (replaces) the content of a named slot using the provided iterator.

func (*Node) Spellcheck

func (n *Node) Spellcheck(v ...bool) *Node

Spellcheck sets the "spellcheck" attribute. If value is omitted, it sets a boolean attribute. If value is provided and false, it sets a string value "false".

func (*Node) Src

func (n *Node) Src(v string) *Node

func (*Node) Srcdoc

func (n *Node) Srcdoc(v string) *Node

func (*Node) Srclang

func (n *Node) Srclang(v string) *Node

func (*Node) Srcset

func (n *Node) Srcset(v string) *Node

func (*Node) Start

func (n *Node) Start(v int) *Node

func (*Node) StaticContent

func (n *Node) StaticContent(fn func() *Node) *Node

StaticContent sets (replaces) the content of the node to the cached output of fn. Subsequent calls return a cached raw byte node, avoiding re-rendering.

The cache key is the function pointer; closures are cached by function address and therefore execute at most once, regardless of captured variables.

func (*Node) Step

func (n *Node) Step(value ...int) *Node

Step adds a "step" attribute. If value is omitted, "any" is used.

func (*Node) String

func (n *Node) String() string

String renders the node to a string.

func (*Node) Style

func (n *Node) Style(v string) *Node

func (*Node) T added in v0.3.0

func (n *Node) T(s string) *Node

T is an alias for Text.

func (*Node) TV added in v0.3.0

func (n *Node) TV(v TypedValue) *Node

TV is an alias for TextValue.

func (*Node) TabIndex

func (n *Node) TabIndex(v int) *Node

func (*Node) Tag

func (n *Node) Tag(tag string) *Node

Tag sets the HTML tag name of the node.

func (*Node) Text

func (n *Node) Text(s string) *Node

Text sets (replaces) the content of the node to a single text node. The content is HTML-escaped during rendering.

func (*Node) TextValue

func (n *Node) TextValue(v TypedValue) *Node

TextValue sets (replaces) the content of the node to a single text node. The content is HTML-escaped during rendering.

func (*Node) Translate

func (n *Node) Translate(v string) *Node

func (*Node) Type

func (n *Node) Type(v string) *Node

func (*Node) UniqueID

func (n *Node) UniqueID() *Node

func (*Node) UnsafeScript

func (n *Node) UnsafeScript()

UnsafeScript enables unsafe <script> rendering.

func (*Node) V added in v0.3.0

func (n *Node) V(name string, value string) *Node

V is an alias for Var.

func (*Node) VV added in v0.3.0

func (n *Node) VV(name string, value string) *Node

VV is an alias for VarValue.

func (*Node) Value

func (n *Node) Value(v TypedValue) *Node

func (*Node) Var

func (n *Node) Var(name string, value string) *Node

Var attaches arbitrary user data (variable) to the node. These variables are not rendered to HTML.

func (*Node) VarValue

func (n *Node) VarValue(name string, value TypedValue) *Node

VarValue attaches arbitrary user data (variable) to the node. These variables are not rendered to HTML.

func (*Node) Vars added in v0.4.0

func (n *Node) Vars() iter.Seq2[string, TypedValue]

Vars returns iterator over active classes.

func (*Node) Viewport

func (n *Node) Viewport(v string) *Node

func (*Node) Width

func (n *Node) Width(v int) *Node

func (*Node) WithSlot added in v0.2.0

func (n *Node) WithSlot(name string, fn func(n *Node, slot *Node))

WithSlot executes fn with the slot's content if the specified slot exists and has content. Otherwise, fn is not called. Slot content is removed before passing it to fn.

func (*Node) Wrap

func (n *Node) Wrap(v string) *Node

func (*Node) X added in v0.3.0

func (n *Node) X(nodes ...*Node) *Node

X is an alias for Content.

type ParseFlag added in v0.5.0

type ParseFlag uint8
const (
	// ParseReuseBuffer allows parsed node values to reference the input buffer directly.
	// When enabled, mutating the original input bytes may corrupt the output.
	ParseReuseBuffer ParseFlag = 1 << iota
	// ParseKeepWhitespace keeps all whitespace text as-is.
	ParseKeepWhitespace
	// ParseKeepEdgeWhitespace keeps whitespace in non-empty text nodes and drops whitespace-only text nodes.
	ParseKeepEdgeWhitespace
	// ParseTopLevelRawContent parses exactly one top-level element and stores its entire inner HTML as one raw child node.
	// If input contains more than one top-level node, Parse returns an error.
	ParseTopLevelRawContent
	// ParseAllowScriptContent allows non-empty <script> content.
	ParseAllowScriptContent
	// ParseKeepComments keeps HTML comments as raw nodes.
	ParseKeepComments
)

type TypedValue

type TypedValue struct {
	// contains filtered or unexported fields
}

TypedValue can hold strings, ints, booleans and floats without allocation.

var Unset TypedValue

Unset represents an empty, unset or removed value.

func Any

func Any(v any) TypedValue

func Bool

func Bool(v bool) TypedValue

func Bytes

func Bytes(b []byte) TypedValue

func Float

func Float(v float64) TypedValue

func Int

func Int(v int) TypedValue

func Int64

func Int64(v int64) TypedValue

func JSON

func JSON(v any) TypedValue

func String

func String(s string) TypedValue

func Uint

func Uint(v uint) TypedValue

func Uint64

func Uint64(v uint64) TypedValue

func (TypedValue) Any

func (v TypedValue) Any() any

func (TypedValue) Bool

func (v TypedValue) Bool() (bool, bool)

func (TypedValue) BoolOrDefault

func (v TypedValue) BoolOrDefault(d bool) bool

func (TypedValue) BoolOrZero

func (v TypedValue) BoolOrZero() bool

func (TypedValue) Bytes

func (v TypedValue) Bytes() ([]byte, bool)

func (TypedValue) BytesOrZero

func (v TypedValue) BytesOrZero() []byte

func (TypedValue) Float64

func (v TypedValue) Float64() (float64, bool)

func (TypedValue) FloatOrDefault

func (v TypedValue) FloatOrDefault(d float64) float64

func (TypedValue) FloatOrZero

func (v TypedValue) FloatOrZero() float64

func (TypedValue) Int64

func (v TypedValue) Int64() (int64, bool)

func (TypedValue) IntOrDefault

func (v TypedValue) IntOrDefault(d int64) int64

func (TypedValue) IntOrZero

func (v TypedValue) IntOrZero() int64

func (TypedValue) JSON

func (v TypedValue) JSON() (any, bool)

func (TypedValue) JSONOrZero

func (v TypedValue) JSONOrZero() any

func (TypedValue) Kind

func (v TypedValue) Kind() ValueKind

func (TypedValue) String

func (v TypedValue) String() (string, bool)

func (TypedValue) StringOrDefault

func (v TypedValue) StringOrDefault(d string) string

func (TypedValue) StringOrZero

func (v TypedValue) StringOrZero() string

func (TypedValue) Uint64

func (v TypedValue) Uint64() (uint64, bool)

func (TypedValue) UintOrDefault

func (v TypedValue) UintOrDefault(d uint64) uint64

func (TypedValue) UintOrZero

func (v TypedValue) UintOrZero() uint64

func (TypedValue) Valid

func (v TypedValue) Valid() bool

Valid returns true if it contains a valid value.

type ValueKind

type ValueKind int
const (
	KindNone ValueKind = iota
	KindAny
	KindBool
	KindInt64
	KindUint64
	KindFloat64
	KindString
	KindJSON
	KindBytes
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL