Documentation ¶
Overview ¶
Package selector contains a css3 selector parser.
The package follows the CSS3 Spec at: http://www.w3.org/TR/css3-selectors/
Index ¶
Constants ¶
const ( // Tagname selector Tag selectorType = iota // Universal selector Universal // Id Selector Id // Class Selector Class // Attribute Selector Attr // Pseudoclass Selector PseudoClass // Pseudoelement Selector PseudoElement )
const ( // Descendant combinator Descendant combinator = iota // Child Combinatory Child // An immediately adjacent sibling combinator AdjacentSibling // General sibling combinator Sibling )
const ( // Test for the presence of the attribute Presence attrMatchType = iota // Test for an exact value for the attribute Exactly // Test that an attribute contains a value in a whitespace seperated list. Contains // Test that an attribute starts with a value or a value with a dash. DashPrefix )
Variables ¶
var (
EOS = fmt.Errorf("End of Selector")
)
Functions ¶
This section is empty.
Types ¶
type Chain ¶
type Chain struct { // The first Sequence of selectors in the Chain. Head Sequence // The rest of the Links in the chain. Tail []Link }
Chain is a chain of sequences joined using Links.
func Selector ¶
Selector parses a string into a Chain. if it encounters a '{' character it stops and returns the Chain and EOS. This is a convenience that allows you to use this to parse selectors from a CSS file or style tag.
func SelectorFromScanner ¶
func SelectorFromScanner(rdr io.ByteScanner) (*Chain, error)
SelectorFromScanner parses an io.ByteScanner into a Chain.
func (*Chain) Specificity ¶
Specificity returns the CSS3 specificity of a Chain.
type Link ¶
type Link struct { // Combinator used to join this link with another Link or Sequence in a Chain. Combinator combinator // Sequence that combinator will join to the previous Link or Sequence in a Chain. Sequence }
Link joins a sequence to another sequence with a combinator.
type Sequence ¶
type Sequence []SimpleSelector
Sequence is a list of SimpleSelectors describing multiple things about an element.
func (Sequence) Specificity ¶
Specificity returns the CSS3 specificity for a given sequence of SimpleSelectors.
type SimpleSelector ¶
type SimpleSelector struct { // The type of Simple Selector. Type selectorType // The Tagname of the SimpleSelector if Type is Tag Tag string // The attribute matching type if Type is Attr AttrMatch attrMatchType // The value to match against if Type is Id, Class, Pseudoclass, Pseudoelement, or Attr Value string // The attribute name if Type is Attr AttrName string }
SimpleSelector describes one thing about an element.
func (SimpleSelector) Match ¶
func (ss SimpleSelector) Match(n *html.Node) bool
Match returns true if this SimpleSelector matches this node false otherwise.
func (SimpleSelector) Specificity ¶
func (ss SimpleSelector) Specificity() int64
Specificity returns the CSS3 specificity for a SimpleSelector.
func (SimpleSelector) String ¶
func (ss SimpleSelector) String() string