Documentation
¶
Index ¶
- Variables
- func AssignDocumentOrder(root *Node)
- func DefaultSelectedIndex(selectNode *Node) int
- func HasDirtySelectedOption(selectNode *Node) bool
- func HasInputType(node *Node, inputType string) bool
- func InitializeElementStates(root *Node)
- func IsChecked(node *Node) bool
- func IsContentEditable(node *Node) bool
- func IsDisabled(node *Node) bool
- func IsEditingHost(node *Node) bool
- func IsPlaceholderShown(node *Node) bool
- func ResetForm(form *Node) bool
- func SameRadioGroup(left, right *Node) bool
- func SelectedIndex(selectNode *Node) int
- func SetLiveValue(node *Node, value string, dirty bool)
- func SetOptionSelected(option *Node, selected bool) bool
- func SetOptionSelectedAt(selectNode *Node, optionIndex int, selected bool) bool
- func SetSelectedIndex(selectNode *Node, selected int)
- func SetSelectedRange(selectNode *Node, start, end int) bool
- func SupportsDisabled(node *Node) bool
- func SupportsPlaceholder(node *Node) bool
- func SynchronizeCheckedAttribute(node *Node, present bool)
- func SynchronizePlaceholderAttribute(node *Node)
- func SynchronizeSelectAttribute(selectNode *Node, name string)
- func SynchronizeSelectChildren(node *Node)
- func SynchronizeSelectedAttribute(option *Node, present bool)
- func SynchronizeTextContent(node *Node)
- func SynchronizeValueAttribute(node *Node)
- func TabIndex(node *Node) (int, bool)
- type Attribute
- type ElementState
- type Node
- func (n *Node) AppendChild(child *Node)
- func (a *Node) Attr(name string) (string, bool)
- func (a *Node) AttrCount() int
- func (a *Node) AttrValue(name string) string
- func (a *Node) Attributes() iter.Seq2[string, string]
- func (n *Node) InsertBefore(child, before *Node)
- func (a *Node) RemoveAttr(name string) bool
- func (n *Node) RemoveChild(child *Node)
- func (a *Node) SetAttr(name, value string) bool
- func (a *Node) SetAttributes(attributes ...Attribute)
- func (n *Node) ShareAttributes(source *Node)
- func (a *Node) SortedAttributes() iter.Seq2[string, string]
- func (n *Node) String() string
- type NodeType
- type Parser
- type StateSet
- type Token
- func (a *Token) Attr(name string) (string, bool)
- func (a *Token) AttrCount() int
- func (a *Token) AttrValue(name string) string
- func (a *Token) Attributes() iter.Seq2[string, string]
- func (a *Token) RemoveAttr(name string) bool
- func (a *Token) SetAttr(name, value string) bool
- func (a *Token) SetAttributes(attributes ...Attribute)
- func (a *Token) SortedAttributes() iter.Seq2[string, string]
- type TokenType
- type Tokenizer
Constants ¶
This section is empty.
Variables ¶
var ErrNestingDepth = errors.New("dom: maximum element depth (512) exceeded")
ErrNestingDepth reports HTML nesting beyond the parser's 512-element limit.
Functions ¶
func AssignDocumentOrder ¶
func AssignDocumentOrder(root *Node)
AssignDocumentOrder records preorder positions without allocating.
func DefaultSelectedIndex ¶
DefaultSelectedIndex returns the effective selection produced by resetting the select from its authored option attributes.
func HasDirtySelectedOption ¶
func HasInputType ¶
func InitializeElementStates ¶
func InitializeElementStates(root *Node)
func IsContentEditable ¶
IsContentEditable resolves the enumerated contenteditable attribute through the element's ancestors.
func IsDisabled ¶
func IsEditingHost ¶
IsEditingHost reports whether node starts a contenteditable region. Nested editable descendants are not independent sequential focus targets.
func IsPlaceholderShown ¶
func ResetForm ¶
ResetForm restores controls owned by form to their authored defaults. The traversal includes controls associated through an explicit form attribute.
func SameRadioGroup ¶
func SelectedIndex ¶
SelectedIndex returns the first live selected option in tree order.
func SetLiveValue ¶
SetLiveValue updates the compact value state used by :placeholder-shown. The string itself remains owned by the generated form control.
func SetOptionSelected ¶
SetOptionSelected updates one option's selectedness as the selected IDL property does. A single-select keeps at most one selected option.
func SetOptionSelectedAt ¶
func SetSelectedIndex ¶
SetSelectedIndex updates live option selectedness. The selected option gets a dirty flag; options deselected as a consequence retain their dirtyness.
func SetSelectedRange ¶
SetSelectedRange applies a user range selection to a multiple select in one mutation pass. Disabled options retain their selectedness because keyboard and pointer input cannot toggle them.
func SupportsDisabled ¶
func SupportsPlaceholder ¶
func SynchronizeCheckedAttribute ¶
SynchronizeCheckedAttribute applies a checked content-attribute mutation to live checkedness while the control's dirty checkedness flag is clear.
func SynchronizePlaceholderAttribute ¶
func SynchronizePlaceholderAttribute(node *Node)
func SynchronizeSelectAttribute ¶
SynchronizeSelectAttribute applies multiple/size mutations to live selectedness using the select element's normalization rules.
func SynchronizeSelectChildren ¶
func SynchronizeSelectChildren(node *Node)
SynchronizeSelectChildren normalizes live selection after an option list changes. Keep the last selected option without resetting defaults or dirtyness.
func SynchronizeSelectedAttribute ¶
SynchronizeSelectedAttribute applies an option selected content-attribute mutation unless that option's live selectedness is dirty.
func SynchronizeTextContent ¶
func SynchronizeTextContent(node *Node)
SynchronizeTextContent updates a textarea's live value state from its child text while the dirty value flag is clear.
func SynchronizeValueAttribute ¶
func SynchronizeValueAttribute(node *Node)
SynchronizeValueAttribute updates live value state from an input value content attribute while the dirty value flag is clear.
Types ¶
type Attribute ¶ added in v0.1.5
type Attribute struct{ Name, Value string }
Attribute is an authored name/value pair. Names retain their exact spelling; the HTML parser applies ASCII folding and foreign-content adjustments.
type ElementState ¶
type ElementState uint16
const ( StateChecked ElementState = 1 << iota StatePlaceholderShown StateIndeterminate StateDirtyChecked StateValueEmpty StateDirtyValue StateDirtySelected )
type Node ¶
type Node struct {
Parent *Node
Data string
Children []*Node
Type NodeType
Order uint32
States StateSet[ElementState]
// contains filtered or unexported fields
}
func FormOwner ¶
FormOwner returns the form associated with a form control. An explicit form attribute takes precedence over the nearest ancestor form.
func NewDocument ¶
func NewDocument() *Node
func NewElement ¶
func Parse ¶
Parse returns an independently owned DOM. Use a retained Parser when the previous DOM can be discarded to avoid allocations after warming its storage. Malformed HTML is repaired using the HTML tree construction rules. As before, sources without a leading doctype/html/head/body are parsed as body fragments.
func (*Node) AppendChild ¶
func (*Node) AttrValue ¶ added in v0.1.5
AttrValue returns an attribute's value, or an empty string if absent.
func (*Node) Attributes ¶
Attributes visits attributes without allocating. Order is unspecified. Removing or updating the currently yielded attribute is allowed; other mutations during iteration are not supported. Pairs are values, never writable storage views.
func (*Node) InsertBefore ¶
func (*Node) RemoveAttr ¶ added in v0.1.4
RemoveAttr removes an attribute, returning whether it was present.
func (*Node) RemoveChild ¶
func (*Node) SetAttr ¶ added in v0.1.4
SetAttr changes an attribute, returning whether its value changed.
func (*Node) SetAttributes ¶ added in v0.1.5
func (a *Node) SetAttributes(attributes ...Attribute)
SetAttributes replaces all attributes with an owned copy and reuses capacity. Duplicate names keep their first value, matching HTML tokenization.
func (*Node) ShareAttributes ¶ added in v0.1.4
ShareAttributes shares source's storage without copying it. Subsequent edits to either node detach its attributes. A nil source clears the attributes. Sharing does not extend the lifetime of parser-owned names or values. Independent destinations may share a read-only source concurrently.
func (*Node) SortedAttributes ¶ added in v0.1.5
SortedAttributes visits attributes in name order. Small lists need no extra storage. Large maps allocate a sorted name buffer for deterministic output. Do not change attributes during iteration.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser builds DOM nodes directly from UTF-8 source. Its zero value is ready to use. Nodes, attributes, child slices and decoded text are reused on the next Parse or Reset call, which invalidates the previous result. A Parser must not be copied after use or used concurrently.
Unchanged text and names borrow the source string. Decoded strings borrow parser storage; they are immutable until the next Parse or Reset call.
type StateSet ¶
type StateSet[T ~uint16] struct { // contains filtered or unexported fields }
StateSet stores explicitly resolved boolean states in two compact bitsets. A valid bit distinguishes a live false value from an uninitialized state.
type Token ¶
func (*Token) AttrValue ¶ added in v0.1.5
AttrValue returns an attribute's value, or an empty string if absent.
func (*Token) Attributes ¶
Attributes visits attributes without allocating. Order is unspecified. Removing or updating the currently yielded attribute is allowed; other mutations during iteration are not supported. Pairs are values, never writable storage views.
func (*Token) RemoveAttr ¶ added in v0.1.5
RemoveAttr removes an attribute, returning whether it was present.
func (*Token) SetAttr ¶ added in v0.1.5
SetAttr changes an attribute, returning whether its value changed.
func (*Token) SetAttributes ¶ added in v0.1.5
func (a *Token) SetAttributes(attributes ...Attribute)
SetAttributes replaces all attributes with an owned copy and reuses capacity. Duplicate names keep their first value, matching HTML tokenization.
func (*Token) SortedAttributes ¶ added in v0.1.5
SortedAttributes visits attributes in name order. Small lists need no extra storage. Large maps allocate a sorted name buffer for deterministic output. Do not change attributes during iteration.
type Tokenizer ¶
type Tokenizer struct {
// contains filtered or unexported fields
}
Tokenizer scans UTF-8 HTML, borrowing unchanged source text. It skips comments and declarations, recovers malformed input, and handles raw text elements. Returned tokens remain valid for the lifetime of the tokenizer.