selector

package
v0.0.0-...-3f75658 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2014 License: Artistic-2.0 Imports: 5 Imported by: 1

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

View Source
const (
	// Tagname selector
	Tag selectorType = iota
	// Universal selector
	Universal
	// Id Selector
	Id
	// Class Selector
	Class
	// Attribute Selector
	Attr
	// Pseudoclass Selector
	PseudoClass
	// Pseudoelement Selector
	PseudoElement
)
View Source
const (
	// Descendant combinator
	Descendant combinator = iota
	// Child Combinatory
	Child
	// An immediately adjacent sibling combinator
	AdjacentSibling
	// General sibling combinator
	Sibling
)
View Source
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

View Source
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

func Selector(sel string) (*Chain, error)

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) Find

func (chn *Chain) Find(n *html.Node) []*html.Node

Find all the nodes in a html.Node tree that match this Selector Chain.

func (*Chain) Specificity

func (chn *Chain) Specificity() int64

Specificity returns the CSS3 specificity of a Chain.

func (*Chain) String

func (chn *Chain) String() string
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.

func (Link) Find

func (l Link) Find(n *html.Node) []*html.Node

Find all the nodes in a html.Node tree that match this Selector Link.

func (Link) String

func (l Link) String() string

type Sequence

type Sequence []SimpleSelector

Sequence is a list of SimpleSelectors describing multiple things about an element.

func (Sequence) Find

func (s Sequence) Find(n *html.Node) []*html.Node

Find finds all Nodes that match this sequence in the tree rooted by n.

func (Sequence) Match

func (s Sequence) Match(n *html.Node) bool

Match returns true if this Sequence matches this node false otherwise.

func (Sequence) Specificity

func (s Sequence) Specificity() int64

Specificity returns the CSS3 specificity for a given sequence of SimpleSelectors.

func (Sequence) String

func (s Sequence) String() string

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL