css: github.com/niklasfasching/css Index | Files

package css

import "github.com/niklasfasching/css"

https://drafts.csswg.org/cssom/#common-serializing-idioms

https://www.w3.org/TR/2018/CR-selectors-3-20180130/#w3cselgrammar

Index

Package Files

css.go escape.go lex.go parse.go selector.go util.go

Variables

var Combinators = map[string]func(Selector, Selector) Selector{
    " ": func(s1, s2 Selector) Selector { return &DescendantSelector{s1, s2} },
    ">": func(s1, s2 Selector) Selector { return &ChildSelector{s1, s2} },
    "+": func(s1, s2 Selector) Selector { return &NextSiblingSelector{s1, s2} },
    "~": func(s1, s2 Selector) Selector { return &SubsequentSiblingSelector{s1, s2} },
    ",": func(s1, s2 Selector) Selector { return &UnionSelector{s1, s2} },
}
var Matchers = map[string]func(string, string) bool{
    "~=": includeMatch,
    "|=": func(av, sv string) bool { return av == sv || strings.HasPrefix(av, sv+"-") },
    "^=": func(av, sv string) bool { return sv != "" && strings.HasPrefix(av, sv) },
    "$=": func(av, sv string) bool { return sv != "" && strings.HasSuffix(av, sv) },
    "*=": func(av, sv string) bool { return strings.Contains(av, sv) },
    "=":  func(av, sv string) bool { return av == sv },
    "":   func(string, string) bool { return true },
}
var PseudoClasses = map[string]func(*html.Node) bool{
    "root":          isRoot,
    "empty":         isEmpty,
    "checked":       func(n *html.Node) bool { return isInput(n) && hasAttribute(n, "checked") },
    "disabled":      func(n *html.Node) bool { return isInput(n) && hasAttribute(n, "disabled") },
    "enabled":       func(n *html.Node) bool { return isInput(n) && !hasAttribute(n, "disabled") },
    "optional":      func(n *html.Node) bool { return isInput(n) && !hasAttribute(n, "required") },
    "required":      func(n *html.Node) bool { return isInput(n) && hasAttribute(n, "required") },
    "read-only":     func(n *html.Node) bool { return isInput(n) && hasAttribute(n, "readonly") },
    "read-write":    func(n *html.Node) bool { return isInput(n) && !hasAttribute(n, "readonly") },
    "first-child":   nthSiblingCompiled(func(n *html.Node) *html.Node { return n.PrevSibling }, "1", false),
    "first-of-type": nthSiblingCompiled(func(n *html.Node) *html.Node { return n.PrevSibling }, "1", true),
    "last-child":    nthSiblingCompiled(func(n *html.Node) *html.Node { return n.NextSibling }, "1", false),
    "last-of-type":  nthSiblingCompiled(func(n *html.Node) *html.Node { return n.NextSibling }, "1", true),
    "only-child":    onlyChild(false),
    "only-of-type":  onlyChild(true),
}
var PseudoFunctions = map[string]func(string) (func(*html.Node) bool, error){
    "not":              nil,
    "nth-child":        nthSibling(func(n *html.Node) *html.Node { return n.PrevSibling }, false),
    "nth-last-child":   nthSibling(func(n *html.Node) *html.Node { return n.NextSibling }, false),
    "nth-of-type":      nthSibling(func(n *html.Node) *html.Node { return n.PrevSibling }, true),
    "nth-last-of-type": nthSibling(func(n *html.Node) *html.Node { return n.NextSibling }, true),
    "contains":         contains,
}

func All Uses

func All(s Selector, n *html.Node) []*html.Node

func EscapeIdentifier Uses

func EscapeIdentifier(unescaped string) (escaped string)

func EscapeString Uses

func EscapeString(unescaped string) (escaped string)

func First Uses

func First(s Selector, n *html.Node) *html.Node

func Unescape Uses

func Unescape(escaped string) (unescaped string)

type AttributeSelector Uses

type AttributeSelector struct {
    Key   string
    Value string
    Type  string
    // contains filtered or unexported fields
}

func (*AttributeSelector) Match Uses

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

func (*AttributeSelector) String Uses

func (s *AttributeSelector) String() string

type ChildSelector Uses

type ChildSelector struct {
    Parent   Selector
    Selector Selector
}

func (*ChildSelector) Match Uses

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

func (*ChildSelector) String Uses

func (s *ChildSelector) String() string

type ClassSelector Uses

type ClassSelector struct{ *AttributeSelector }

func (*ClassSelector) String Uses

func (s *ClassSelector) String() string

type DescendantSelector Uses

type DescendantSelector struct {
    Ancestor Selector
    Selector Selector
}

func (*DescendantSelector) Match Uses

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

func (*DescendantSelector) String Uses

func (s *DescendantSelector) String() string

type ElementSelector Uses

type ElementSelector struct {
    Element string
}

func (*ElementSelector) Match Uses

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

func (*ElementSelector) String Uses

func (s *ElementSelector) String() string

type IDSelector Uses

type IDSelector struct{ *AttributeSelector }

func (*IDSelector) String Uses

func (s *IDSelector) String() string

type NextSiblingSelector Uses

type NextSiblingSelector struct {
    Sibling  Selector
    Selector Selector
}

func (*NextSiblingSelector) Match Uses

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

func (*NextSiblingSelector) String Uses

func (s *NextSiblingSelector) String() string

type PseudoFunctionSelector Uses

type PseudoFunctionSelector struct {
    Name string
    Args string
    // contains filtered or unexported fields
}

func (*PseudoFunctionSelector) Match Uses

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

func (*PseudoFunctionSelector) String Uses

func (s *PseudoFunctionSelector) String() string

type PseudoSelector Uses

type PseudoSelector struct {
    Name string
    // contains filtered or unexported fields
}

func (*PseudoSelector) Match Uses

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

func (*PseudoSelector) String Uses

func (s *PseudoSelector) String() string

type Selector Uses

type Selector interface {
    Match(*html.Node) bool
    String() string
}

func Compile Uses

func Compile(selector string) (Selector, error)

func MustCompile Uses

func MustCompile(selector string) Selector

type SelectorSequence Uses

type SelectorSequence struct {
    Selectors []Selector
}

func (*SelectorSequence) Match Uses

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

func (*SelectorSequence) String Uses

func (s *SelectorSequence) String() string

type SubsequentSiblingSelector Uses

type SubsequentSiblingSelector struct {
    Sibling  Selector
    Selector Selector
}

func (*SubsequentSiblingSelector) Match Uses

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

func (*SubsequentSiblingSelector) String Uses

func (s *SubsequentSiblingSelector) String() string

type UnionSelector Uses

type UnionSelector struct {
    SelectorA Selector
    SelectorB Selector
}

func (*UnionSelector) Match Uses

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

func (*UnionSelector) String Uses

func (s *UnionSelector) String() string

type UniversalSelector Uses

type UniversalSelector struct {
    Element string
}

func (*UniversalSelector) Match Uses

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

func (*UniversalSelector) String Uses

func (s *UniversalSelector) String() string

Package css imports 8 packages (graph). Updated 2019-06-04. Refresh now. Tools for package owners.