Documentation ¶
Index ¶
- func Map[T any](node Node, f func(n Node) T) []T
- type Match
- type Node
- func (n Node) AttrVal(attr string) (string, bool)
- func (n Node) Children() []Node
- func (n Node) Clone() Node
- func (n Node) CloneDetach() Node
- func (node Node) Each(f func(int, Node))
- func (node Node) EachBreak(f func(int, Node) bool)
- func (n Node) Find(m Match) Node
- func (n Node) FindAll(m Match) Node
- func (n Node) FindAllWithDepth(m Match, depth int) Node
- func (n Node) FindChild(ms ...Match) Node
- func (n Node) FindDescendant(ms ...Match) Node
- func (n Node) FindWithDepth(m Match, depth int) Node
- func (n Node) First() Node
- func (n Node) FirstChild() Node
- func (n Node) Get(index int) Node
- func (n Node) GetE(index int) (Node, bool)
- func (n Node) Html() (string, error)
- func (n Node) Last() Node
- func (n Node) LastChild() Node
- func (n Node) Len() int
- func (n Node) NextSibling() Node
- func (n Node) Parent() Node
- func (n Node) PrevSibling() Node
- func (n Node) Text() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Match ¶
func Atom ¶ added in v0.9.0
Atom returns a Match that returns true if the given node's atom is the given atom.
func HasAttrVal ¶
HasAttrVal returns a Match that returns true if the given node has the given attribute and the attribute's value is the given value.
type Node ¶ added in v0.2.0
Node is a wrapper of html.Node.
func MakeTree ¶ added in v0.9.0
MakeTree makes a new root node and appends given nodes as its children.
Given nodes are cloned and detached from their original parent. Original nodes are not modified.
func (Node) Clone ¶ added in v0.9.0
Clone returns a copy of the node.
It does not a deep copy about the connected nodes. So child, parent, and sibling are same pointers as the original one. Attributes are copied.
func (Node) CloneDetach ¶ added in v0.9.0
CloneDetach returns a copy of the node.
The node is detached from its parent and siblings. It has same children as the original one.
func (Node) EachBreak ¶ added in v0.6.0
EachBreak calls the function f for each node in the node's children. If f returns true, the iteration is stopped.
func (Node) Find ¶ added in v0.2.0
Find finds nodes that match the given condition.
It returns first node that matches the condition on each branch. If no node is found, it returns an empty node. Found nodes are bundled in a new root node.
func (Node) FindAll ¶ added in v0.9.0
FindAll finds nodes that match the given condition.
It returns all node that matches the condition. If no node is found, it returns an empty node. Found nodes are bundled in a new root node.
func (Node) FindAllWithDepth ¶ added in v0.9.0
FindAllWithDepth finds nodes that match the given condition.
If depth is more than 0, it searches descendants up to the depth. If depth is -1, it searches all descendants.
It returns all node that matches the condition. If no node is found, it returns an empty node. Found nodes are bundled in a new root node.
func (Node) FindChild ¶ added in v0.5.0
FindChild finds a node that matches the given conditions.
It searches for a node that matches each condition in ms, but only among direct children of the previous matching node. For example, if len(ms) == 2, it searches a node that matches ms[1] that is a direct child of a node that matches ms[0].
It returns first node that matches the condition on each branch. If no node is found, it returns an empty node. Found nodes are bundled in a new root node.
func (Node) FindDescendant ¶ added in v0.5.0
FindDescendant finds a node that matches the given conditions.
It searches for a node that matches each condition in ms, but only among descendants of the previous matching node. For example, if len(ms) == 2, it searches a node that matches ms[1] that is a descendant of a node that matches ms[0].
It returns first node that matches the condition on each branch. If no node is found, it returns an empty node. Found nodes are bundled in a new root node.
func (Node) FindWithDepth ¶ added in v0.9.0
FindWithDepth finds nodes that match the given condition.
If depth is more than 0, it searches descendants up to the depth. If depth is -1, it searches all descendants.
It returns first node that matches the condition on each branch. If no node is found, it returns an empty node. Found nodes are bundled in a new root node.
func (Node) FirstChild ¶ added in v0.2.0
FirstChild returns the first child node.
func (Node) Get ¶ added in v0.8.0
Get returns the child node at the given index.
You can use negative index same as slices. If the index is out of range, it returns a new empty node and false.
func (Node) GetE ¶ added in v0.8.0
GetE returns the child node at the given index.
You can use negative index same as slices. Second return value is true if index is in range. If the index is out of range, it returns a new empty node and false.
func (Node) NextSibling ¶ added in v0.2.0
NextSibling returns the next sibling node.
func (Node) PrevSibling ¶ added in v0.2.0
PrevSibling returns the previous sibling node.