dom

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: MIT Imports: 4 Imported by: ? 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

Overview

Package dom provides a Paper-friendly wrapper over golang.org/x/net/html.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsBlockTag

func IsBlockTag(tag string) bool

IsBlockTag reports whether the given tag name is block-level by the HTML5 default UA stylesheet.

Types

type Document

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

Document is the parsed HTML document.

func Parse

func Parse(src string) (*Document, error)

Parse parses an HTML string and returns a Document.

func (*Document) HTMLElement

func (d *Document) HTMLElement() *Node

HTMLElement returns the <html> element wrapped as a *Node, or nil when the document has no html element. Used by the cascade seed so :root and html-level CSS rules apply (Document.Walk starts at body, not the root).

func (*Document) Root

func (d *Document) Root() *html.Node

Root returns the underlying html.Node for direct access when needed.

func (*Document) StyleSources

func (d *Document) StyleSources() (string, []string)

StyleSources returns both the concatenated inline <style> text and the ordered list of <link rel="stylesheet"> href values (in DOM order). External stylesheet content is NOT loaded here; the caller is responsible for resolving each href via a safe resolver.

func (*Document) StyleText

func (d *Document) StyleText() string

StyleText returns all concatenated <style> block contents. Backward-compatible: returns only inline <style> text, not the contents of <link rel="stylesheet"> sheets. Callers needing both should use StyleSources.

func (*Document) ValidateLimits

func (d *Document) ValidateLimits(l htmllimits.Limits) error

ValidateLimits checks DOM depth and node count without invoking a callback.

func (*Document) Walk

func (d *Document) Walk(fn func(*Node) bool)

Walk performs a depth-first traversal starting from the document body. The callback returns true to continue traversal, false to stop.

func (*Document) WalkWithLimits

func (d *Document) WalkWithLimits(l htmllimits.Limits, fn func(*Node) bool) error

WalkWithLimits performs a depth-first traversal starting from the document body while enforcing DOM resource limits.

type Node

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

Node wraps a raw html.Node with Paper-friendly accessors.

func (*Node) Attr

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

Attr returns the value of the named attribute, or "" if absent.

func (*Node) Children

func (n *Node) Children() []*Node

Children returns the direct child Nodes.

func (*Node) InlineStyle

func (n *Node) InlineStyle() string

InlineStyle returns the value of the style="" attribute.

func (*Node) IsBlock

func (n *Node) IsBlock() bool

IsBlock returns whether this element is block-level by HTML5 default.

func (*Node) IsInline

func (n *Node) IsInline() bool

IsInline returns whether this element renders inline by HTML5 default.

func (*Node) RawNode

func (n *Node) RawNode() *html.Node

RawNode returns the underlying golang.org/x/net/html.Node. Callers needing cascadia selector matching can use this directly.

func (*Node) Tag

func (n *Node) Tag() string

Tag returns the element tag name (lowercase) or "" for text nodes.

func (*Node) TextContent

func (n *Node) TextContent() string

TextContent returns the concatenated text of all descendant text nodes. Whitespace is collapsed unless the element is inside <pre>.

Jump to

Keyboard shortcuts

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