func Filter(nodes []*html.Node, m Matcher) (result []*html.Node)
Filter returns the nodes that match m.
func Query(n *html.Node, m Matcher) *html.Node
Query returns the first node that matches m, from the descendants of n. If none matches, it returns nil.
func QueryAll(n *html.Node, m Matcher) []*html.Node
QueryAll returns a slice of all the nodes that match m, from the descendants of n.
Matcher is the interface for basic selector functionality. Match returns whether a selector matches n.
type Matcher interface { Match(n *html.Node) bool }
Sel is the interface for all the functionality provided by selectors.
type Sel interface { Matcher Specificity() Specificity // Returns a CSS input compiling to this selector. String() string // Returns a pseudo-element, or an empty string. PseudoElement() string }
func Parse(sel string) (Sel, error)
Parse parses a selector. Use `ParseWithPseudoElement` if you need support for pseudo-elements.
func ParseWithPseudoElement(sel string) (Sel, error)
ParseWithPseudoElement parses a single selector, with support for pseudo-element.
A Selector is a function which tells whether a node matches or not.
This type is maintained for compatibility; I recommend using the newer and more idiomatic interfaces Sel and Matcher.
type Selector func(*html.Node) bool
func Compile(sel string) (Selector, error)
Compile parses a selector and returns, if successful, a Selector object that can be used to match against html.Node objects.
func MustCompile(sel string) Selector
MustCompile is like Compile, but panics instead of returning an error.
func (s Selector) Filter(nodes []*html.Node) (result []*html.Node)
Filter returns the nodes in nodes that match the selector.
func (s Selector) Match(n *html.Node) bool
Match returns true if the node matches the selector.
func (s Selector) MatchAll(n *html.Node) []*html.Node
MatchAll returns a slice of the nodes that match the selector, from n and its children.
func (s Selector) MatchFirst(n *html.Node) *html.Node
MatchFirst returns the first node that matches s, from n and its children.
A SelectorGroup is a list of selectors, which matches if any of the individual selectors matches.
type SelectorGroup []Sel
func ParseGroup(sel string) (SelectorGroup, error)
ParseGroup parses a selector, or a group of selectors separated by commas. Use `ParseGroupWithPseudoElements` if you need support for pseudo-elements.
func ParseGroupWithPseudoElements(sel string) (SelectorGroup, error)
ParseGroupWithPseudoElements parses a selector, or a group of selectors separated by commas. It supports pseudo-elements.
func (s SelectorGroup) Match(n *html.Node) bool
Match returns true if the node matches one of the single selectors.
func (c SelectorGroup) String() string
Specificity is the CSS specificity as defined in https://www.w3.org/TR/selectors/#specificity-rules with the convention Specificity = [A,B,C].
type Specificity [3]int
func (s Specificity) Add(other Specificity) Specificity
func (s Specificity) Less(other Specificity) bool
returns `true` if s < other (strictly), false otherwise