Documentation ¶
Overview ¶
Package htree is a collection of tools for working with trees of html.Nodes.
Index ¶
- func ElAttr(node *html.Node, key string) string
- func ElClassContains(node *html.Node, probe string) bool
- func Find(node *html.Node, pred func(*html.Node) bool) *html.Node
- func FindAll(node *html.Node, pred func(*html.Node) bool, f func(*html.Node) error) error
- func FindAllChildEls(node *html.Node, pred func(*html.Node) bool, f func(*html.Node) error) error
- func FindAllChildren(node *html.Node, pred func(*html.Node) bool, f func(*html.Node) error) error
- func FindAllEls(node *html.Node, pred func(*html.Node) bool, f func(*html.Node) error) error
- func FindEl(node *html.Node, pred func(*html.Node) bool) *html.Node
- func Prune(node *html.Node, pred func(*html.Node) bool) *html.Node
- func Text(node *html.Node) (string, error)
- func Walk(node *html.Node, f func(*html.Node) error) error
- func WriteText(w io.Writer, node *html.Node) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ElClassContains ¶
ElClassContains tells whether `node` has a `class` attribute containing the class name `probe`.
func Find ¶
Find finds the first node, in a depth-first search of the tree rooted at `node`, satisfying the given predicate.
func FindAll ¶
FindAll walks the tree rooted at `node` in preorder, depth-first fashion. It tests each node in the tree with `pred`. Any node that passes the test causes FindAll to (a) call `f` on the node, and (b) skip walking the node's subtree.
If any call to `f` returns an error, FindAll aborts the walk and returns the error.
To continue walking the subtree of a node `n` that passes `pred`, call FindAllChildren(n, pred, f) in the body of `f`.
func FindAllChildEls ¶
FindAllChildEls is the same as FindAllEls but operates only on the children of `node`, not `node` itself.
func FindAllChildren ¶
FindAllChildren is the same as FindAll but operates only on the children of `node`, not `node` itself.
func FindAllEls ¶
FindAllEls is like FindAll but calls `pred`, and perhaps `f`, only for nodes with type `ElementNode`.
To continue walking the subtree of a node `n` that passes `pred`, call FindAllChildEls(n, pred, f) in the body of `f`.
func FindEl ¶
FindEl finds the first `ElementNode`-typed node, in a depth-first search of the tree rooted at `node`, satisfying the given predicate.
func Prune ¶
Prune returns a copy of `node` and its children, minus any subnodes that cause the supplied predicate to return true. If `node` itself is pruned, the return value is nil.
func Text ¶
Text returns the content of the tree rooted at `node` as plain text. HTML entities are decoded, and <br> nodes are turned into newlines.
Types ¶
This section is empty.