dom

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func DefaultSelectedIndex(selectNode *Node) int

DefaultSelectedIndex returns the effective selection produced by resetting the select from its authored option attributes.

func HasDirtySelectedOption

func HasDirtySelectedOption(selectNode *Node) bool

func HasInputType

func HasInputType(node *Node, inputType string) bool

func InitializeElementStates

func InitializeElementStates(root *Node)

func IsChecked

func IsChecked(node *Node) bool

func IsContentEditable

func IsContentEditable(node *Node) bool

IsContentEditable resolves the enumerated contenteditable attribute through the element's ancestors.

func IsDisabled

func IsDisabled(node *Node) bool

func IsEditingHost

func IsEditingHost(node *Node) bool

IsEditingHost reports whether node starts a contenteditable region. Nested editable descendants are not independent sequential focus targets.

func IsPlaceholderShown

func IsPlaceholderShown(node *Node) bool

func ResetForm

func ResetForm(form *Node) bool

ResetForm restores controls owned by form to their authored defaults. The traversal includes controls associated through an explicit form attribute.

func SameRadioGroup

func SameRadioGroup(left, right *Node) bool

func SelectedIndex

func SelectedIndex(selectNode *Node) int

SelectedIndex returns the first live selected option in tree order.

func SetLiveValue

func SetLiveValue(node *Node, value string, dirty bool)

SetLiveValue updates the compact value state used by :placeholder-shown. The string itself remains owned by the generated form control.

func SetOptionSelected

func SetOptionSelected(option *Node, selected bool) bool

SetOptionSelected updates one option's selectedness as the selected IDL property does. A single-select keeps at most one selected option.

func SetOptionSelectedAt

func SetOptionSelectedAt(selectNode *Node, optionIndex int, selected bool) bool

func SetSelectedIndex

func SetSelectedIndex(selectNode *Node, selected int)

SetSelectedIndex updates live option selectedness. The selected option gets a dirty flag; options deselected as a consequence retain their dirtyness.

func SetSelectedRange

func SetSelectedRange(selectNode *Node, start, end int) bool

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 SupportsDisabled(node *Node) bool

func SupportsPlaceholder

func SupportsPlaceholder(node *Node) bool

func SynchronizeCheckedAttribute

func SynchronizeCheckedAttribute(node *Node, present bool)

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

func SynchronizeSelectAttribute(selectNode *Node, name string)

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

func SynchronizeSelectedAttribute(option *Node, present bool)

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.

func TabIndex

func TabIndex(node *Node) (int, bool)

TabIndex parses the global tabindex attribute as a valid signed integer.

Types

type ElementState

type ElementState uint16
const (
	StateChecked ElementState = 1 << iota
	StatePlaceholderShown
	StateIndeterminate
	StateDirtyChecked
	StateValueEmpty
	StateDirtyValue
	StateDirtySelected
)

type Node

type Node struct {
	Attributes map[string]string
	Parent     *Node
	Data       string

	Children []*Node
	Type     NodeType
	Order    uint32
	States   StateSet[ElementState]
	// contains filtered or unexported fields
}

func FormOwner

func FormOwner(node *Node) *Node

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 NewElement(tag string, attrs map[string]string) *Node

func NewText

func NewText(text string) *Node

func Parse

func Parse(input string) (*Node, error)

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 (n *Node) AppendChild(child *Node)

func (*Node) Attr

func (n *Node) Attr(name string) (string, bool)

func (*Node) InsertBefore

func (n *Node) InsertBefore(child, before *Node)

func (*Node) RemoveChild

func (n *Node) RemoveChild(child *Node)

func (*Node) String

func (n *Node) String() string

type NodeType

type NodeType int
const (
	DocumentNode NodeType = iota
	ElementNode
	TextNode
)

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.

func (*Parser) Parse

func (p *Parser) Parse(input string) (root *Node, err error)

Parse replaces the previous result. Once capacity is sufficient, parsing reuses all storage, including entity decoding and malformed-tree repairs.

func (*Parser) Reset

func (p *Parser) Reset()

Reset invalidates the last DOM and releases source references while retaining reusable capacity. Assign Parser{} to release the retained capacity as well.

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.

func (*StateSet[T]) Clear

func (s *StateSet[T]) Clear(flag T)

func (StateSet[T]) Get

func (s StateSet[T]) Get(flag T) (bool, bool)

func (*StateSet[T]) Set

func (s *StateSet[T]) Set(flag T, value bool)

type Token

type Token struct {
	Attributes map[string]string
	Data       string
	Type       TokenType
}

type TokenType

type TokenType int
const (
	TokenError TokenType = iota
	TokenEOF
	TokenText
	TokenStartTag
	TokenEndTag
	TokenSelfClosingTag
)

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.

func NewTokenizer

func NewTokenizer(input string) *Tokenizer

func (*Tokenizer) Next

func (t *Tokenizer) Next() (Token, error)

Jump to

Keyboard shortcuts

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