Documentation ¶
Overview ¶
Package selector is an implementation of CSS selectors.
Index ¶
- func Filter(nodes []*html.Node, m Matcher) (result []*html.Node)
- func MatchAll(n *html.Node, m Matcher) []*html.Node
- func MatchFirst(n *html.Node, m Matcher) *html.Node
- func Query(n *html.Node, m Matcher) *html.Node
- func QueryAll(n *html.Node, m Matcher) []*html.Node
- type Matcher
- type Sel
- type SelectorGroup
- type Specificity
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MatchAll ¶
MatchAll returns a slice of the nodes that match the selector, from n and its children.
func MatchFirst ¶
MatchFirst returns the first node that matches s, from n and its children.
Types ¶
type Matcher ¶
Matcher is the interface for basic selector functionality. Match returns whether a selector matches n.
type Sel ¶
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 }
Sel is the interface for all the functionality provided by selectors.
type SelectorGroup ¶
type SelectorGroup []Sel
A SelectorGroup is a list of selectors, which matches if any of the individual selectors matches.
func MustCompile ¶
func MustCompile(sel string) SelectorGroup
MustCompile is like ParseGroup, but panics instead of returning an error.
func ParseGroup ¶
func ParseGroup(sel string) (SelectorGroup, error)
ParseGroup parses a selector, or a group of selectors separated by commas. It supports pseudo-elements.
func (SelectorGroup) Match ¶
func (s SelectorGroup) Match(n *html.Node) bool
Match returns true if the node matches one of the single selectors.
func (SelectorGroup) String ¶
func (c SelectorGroup) String() string
type Specificity ¶
type Specificity [3]int
Specificity is the CSS specificity as defined in https://www.w3.org/TR/selectors/#specificity-rules with the convention Specificity = [A,B,C].
func (Specificity) Add ¶
func (s Specificity) Add(other Specificity) Specificity
func (Specificity) Less ¶
func (s Specificity) Less(other Specificity) bool
returns `true` if s < other (strictly), false otherwise