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(tree *html.Node, pred func(*html.Node) bool) *html.Node
- func FindEl(tree *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 WriteText(w io.Writer, node *html.Node) error
- type Seq
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 given tree, satisfying the given predicate.
func FindEl ¶
FindEl finds the first `ElementNode`-typed node, in a depth-first search of the tree, 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.
Types ¶
type Seq ¶
Seq is the type of an iterator over HTML-tree nodes.
func FindAll ¶
FindAll produces an iterator over the nodes in the tree that satisfy the given predicate, skipping that node's children.
To continue walking the subtree of a node `n` that passes `pred`, call `FindAllChildren(n, pred)`. Example:
for n := range FindAll(tree, pred) { doSomething(n, pred) }
And elsewhere:
func doSomething(n *html.Node, pred func(*html.Node) bool) { // ...do something with n... for child := range FindAllChildren(n, pred) { doSomething(child, pred) } }
func FindAllChildEls ¶
FindAllChildEls is the same as FindAllEls but operates only on the children of `node`, not `node` itself.
As with FindAll, the children of a node that passes `pred` are skipped. To continue walking the subtree of a node `n` that passes `pred`, call `FindAllChildEls(n, pred)`.
func FindAllChildren ¶
FindAllChildren is the same as FindAll but operates only on the children of `node`, not `node` itself.
As with FindAll, the children of a node that passes `pred` are skipped. To continue walking the subtree of a node `n` that passes `pred`, call `FindAllChildren(n, pred)`.
func FindAllEls ¶
FindAllEls is like FindAll but calls `pred` only for nodes with type `ElementNode`.
As with FindAll, the children of a node that passes `pred` are skipped. To continue walking the subtree of a node `n` that passes `pred`, call `FindAllChildEls(n, pred)`.