package cascadia
import "github.com/andybalholm/cascadia"
Package cascadia is an implementation of CSS selectors.
Index ¶
- func Filter(nodes []*html.Node, m Matcher) (result []*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 Selector
- func Compile(sel string) (Selector, error)
- func MustCompile(sel string) Selector
- func (s Selector) Filter(nodes []*html.Node) (result []*html.Node)
- func (s Selector) Match(n *html.Node) bool
- func (s Selector) MatchAll(n *html.Node) []*html.Node
- func (s Selector) MatchFirst(n *html.Node) *html.Node
- type SelectorGroup
- type Specificity
Functions ¶
func Filter ¶
Filter returns the nodes that match m.
func Query ¶
Query returns the first node that matches m, from the descendants of n. If none matches, it returns nil.
func QueryAll ¶
QueryAll returns a slice of all the nodes that match m, from the descendants of n.
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 }
Sel is the interface for all the functionality provided by selectors. It is currently the same as Matcher, but other methods may be added in the future.
func Parse ¶
Parse parses a selector.
type Selector ¶
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.
func Compile ¶
Compile parses a selector and returns, if successful, a Selector object that can be used to match against html.Node objects.
func MustCompile ¶
MustCompile is like Compile, but panics instead of returning an error.
func (Selector) Filter ¶
Filter returns the nodes in nodes that match the selector.
func (Selector) Match ¶
Match returns true if the node matches the selector.
func (Selector) MatchAll ¶
MatchAll returns a slice of the nodes that match the selector, from n and its children.
func (Selector) MatchFirst ¶
MatchFirst returns the first node that matches s, from n and its children.
type SelectorGroup ¶
type SelectorGroup []Sel
A SelectorGroup is a list of selectors, which matches if any of the individual selectors matches.
func ParseGroup ¶
func ParseGroup(sel string) (SelectorGroup, error)
ParseGroup parses a selector, or a group of selectors separated by commas.
func (SelectorGroup) Match ¶
func (s SelectorGroup) Match(n *html.Node) bool
Match returns true if the node matches one of the single selectors.
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
Source Files ¶
parser.go selector.go specificity.go
Directories ¶
Path | Synopsis |
---|---|
fuzz |
- Version
- v1.1.0
- Published
- Sep 21, 2019
- Platform
- js/wasm
- Imports
- 7 packages
- Last checked
- now –
Tools for package owners.