Documentation ¶
Index ¶
- Variables
- func IsLiteral(token Token, char string) bool
- func ParseNth(input []Token) *[2]int
- func Serialize(l []Token) string
- func SplitOnComma(tokens []Token) [][]Token
- type AtKeyword
- type AtRule
- type Color
- type ColorType
- type Comment
- type Compound
- func ParseBlocksContents(input []Token, skipWhitespace bool) []Compound
- func ParseBlocksContentsString(css string) []Compound
- func ParseDeclarationList(input []Token, skipComments, skipWhitespace bool) []Compound
- func ParseDeclarationListString(css string, skipComments, skipWhitespace bool) []Compound
- func ParseOneDeclaration(input []Token) Compound
- func ParseRuleList(input []Token, skipComments, skipWhitespace bool) []Compound
- func ParseStylesheet(input []Token, skipComments, skipWhitespace bool) []Compound
- func ParseStylesheetBytes(input []byte, skipComments, skipWhitespace bool) []Compound
- type CurlyBracketsBlock
- type Declaration
- type Dimension
- type FunctionBlock
- type Hash
- type Ident
- type Kind
- type Literal
- type Number
- type ParenthesesBlock
- type ParseError
- type Percentage
- type Pos
- type QualifiedRule
- type RGBA
- type SquareBracketsBlock
- type String
- type Token
- type TokensIter
- type URL
- type UnicodeRange
- type Whitespace
Constants ¶
This section is empty.
Variables ¶
var ( // ColorKeywords maps color names to RGBA values ColorKeywords = map[string]Color{} )
Functions ¶
func ParseNth ¶
Parse <An+B> (see <http://drafts.csswg.org/csswg/css-syntax-3/#anb>), as found in `:nth-child()` and related selector pseudo-classes.
Returns [a, b] or nil
func SplitOnComma ¶ added in v0.0.10
Split a list of tokens on commas, ie on [LiteralToken].
Types ¶
type AtKeyword ¶ added in v0.0.10
type AtKeyword struct {
// contains filtered or unexported fields
}
type AtRule ¶
type AtRule struct { AtKeyword string QualifiedRule }
type Color ¶
func ParseColor ¶
Parse a color value as defined in `CSS Color Level 3 <http://www.w3.org/TR/css3-color/>`. Returns :
- zero Color if the input is not a valid color value. (No error is returned.)
- CurrentColor for the *currentColor* keyword
- RGBA color for every other values (including keywords, HSL && HSLA.) The alpha channel is clipped to [0, 1] but red, green, or blue can be out of range (eg. “rgb(-10%, 120%, 0%)“ is represented as “(-0.1, 1.2, 0, 1)“.
func ParseColorString ¶
ParseColorString tokenize the input before calling `ParseColor`.
type Compound ¶ added in v0.0.10
type Compound interface { Pos() Pos // contains filtered or unexported methods }
Compound is a compound CSS chunk, like a declaration or a qualified rule.
func ParseBlocksContents ¶ added in v0.0.10
ParseBlocksContents parses a block’s contents.
This is used e.g. for the QualifiedRule content of a style rule or '@page' rule, or for the 'style' attribute of an HTML element.
In contexts that don’t expect any at-rule and/or qualified rule, all AtRule and QualifiedRule objects should simply be rejected as invalid.
func ParseBlocksContentsString ¶ added in v0.0.10
ParseBlocksContentsString tokenizes `css` and calls `ParseBlocksContents`.
func ParseDeclarationList ¶
Parse a `declaration list` (which may also contain at-rules). This is used e.g. for the `QualifiedRule.content` of a style rule or “@page“ rule, or for the “style“ attribute of an HTML element.
In contexts that don’t expect any at-rule, all `AtRule` objects should simply be rejected as invalid.
If `skipComments`, ignore CSS comments at the top-level of the list. If `skipWhitespace`, ignore whitespace at the top-level of the list. Whitespace is still preserved in the `Declaration.value` of declarations and the `AtRule.prelude` and `AtRule.content` of at-rules.
func ParseDeclarationListString ¶
ParseDeclarationListString tokenizes `css` and calls `ParseDeclarationList`.
func ParseOneDeclaration ¶
Parse a single `declaration`, returning a ParseError or a Declaration
This is used e.g. for a declaration in an `@supports <http://drafts.csswg.org/csswg/css-conditional/#at-supports>. Any whitespace or comment before the “:“ colon is dropped.
func ParseRuleList ¶
Parse a non-top-level `rule list`.
This is used for parsing the `AtRule.content` of nested rules like “@media“. This differs from `ParseStylesheet` in that top-level “<!--“ and “-->“ tokens are not ignored.
If [skipComments] is true, ignores CSS comments at the top-level of the list.
If [skipWhitespace] is true, ignores whitespace at the top-level of the list. Whitespace are still preserved in the `QualifiedRule.Prelude` and the `QualifiedRule.Content` of rules.
func ParseStylesheet ¶
Parse a stylesheet from tokens.
This is used e.g. for a “<style>“ HTML element. This differs from `ParseRuleList` in that top-level “<!--“ && “-->“ tokens are ignored. This is a legacy quirk for the “<style>“ HTML element.
func ParseStylesheetBytes ¶
ParseStylesheetBytes tokenizes `input` and calls `ParseStylesheet`.
type CurlyBracketsBlock ¶
type CurlyBracketsBlock listVal
func (CurlyBracketsBlock) Kind ¶ added in v0.0.10
func (CurlyBracketsBlock) Kind() Kind
func (CurlyBracketsBlock) Pos ¶ added in v0.0.10
func (v CurlyBracketsBlock) Pos() Pos
type Declaration ¶
type Declaration struct { Name string Value []Token Important bool // contains filtered or unexported fields }
func (Declaration) Pos ¶ added in v0.0.10
func (t Declaration) Pos() Pos
type Dimension ¶ added in v0.0.10
type Dimension struct { Unit string // contains filtered or unexported fields }
func NewDimension ¶ added in v0.0.10
type FunctionBlock ¶
type FunctionBlock struct { Name string // contains filtered or unexported fields }
func NewFunctionBlock ¶ added in v0.0.10
func NewFunctionBlock(pos Pos, name string, arguments []Token) FunctionBlock
func (FunctionBlock) Kind ¶ added in v0.0.10
func (FunctionBlock) Kind() Kind
func (FunctionBlock) Pos ¶ added in v0.0.10
func (v FunctionBlock) Pos() Pos
type Literal ¶ added in v0.0.10
type Literal struct {
// contains filtered or unexported fields
}
Either a delimiter or raw value
func NewLiteral ¶ added in v0.0.10
type Number ¶ added in v0.0.10
type Number struct {
// contains filtered or unexported fields
}
type ParenthesesBlock ¶
type ParenthesesBlock listVal
compound values
func (ParenthesesBlock) Kind ¶ added in v0.0.10
func (ParenthesesBlock) Kind() Kind
func (ParenthesesBlock) Pos ¶ added in v0.0.10
func (v ParenthesesBlock) Pos() Pos
type ParseError ¶
type ParseError struct { Message string // contains filtered or unexported fields }
special token used for parse errors
func (ParseError) Kind ¶
func (ParseError) Kind() Kind
func (ParseError) Pos ¶ added in v0.0.10
func (v ParseError) Pos() Pos
type Percentage ¶ added in v0.0.10
type Percentage struct {
// contains filtered or unexported fields
}
func (Percentage) IsInt ¶ added in v0.0.10
func (tk Percentage) IsInt() bool
IsInt returns true for numerical token with integer value.
func (Percentage) Kind ¶ added in v0.0.10
func (Percentage) Kind() Kind
func (Percentage) Pos ¶ added in v0.0.10
func (v Percentage) Pos() Pos
type Pos ¶ added in v0.0.2
type Pos struct {
Line, Column int
}
Pos is the position of a token in the input CSS file
type QualifiedRule ¶
type QualifiedRule struct {
Prelude, Content []Token
// contains filtered or unexported fields
}
func (QualifiedRule) Pos ¶ added in v0.0.10
func (t QualifiedRule) Pos() Pos
type RGBA ¶
values in [-1, 1]
func (RGBA) RGBA ¶
RGBA returns the alpha-premultiplied red, green, blue and alpha values for the color. Each value ranges within [0, 0xffff], but is represented by a uint32 so that multiplying by a blend factor up to 0xffff will not overflow.
An alpha-premultiplied color component c has been scaled by alpha (a), so has valid values 0 <= c <= a.
type SquareBracketsBlock ¶
type SquareBracketsBlock listVal
func (SquareBracketsBlock) Kind ¶ added in v0.0.10
func (SquareBracketsBlock) Kind() Kind
func (SquareBracketsBlock) Pos ¶ added in v0.0.10
func (v SquareBracketsBlock) Pos() Pos
type Token ¶
Token is a CSS component value, used to build declarations
func ParseFunction ¶ added in v0.0.10
ParseFunction parses functional notation.
Return “(name, args)“ if the given token is a function with comma or space-separated arguments. Return zero values otherwise.
func ParseOneComponentValue ¶
Parse a single `component value`. This is used e.g. for an attribute value referred to by “attr(foo length)“.
func RemoveWhitespace ¶ added in v0.0.10
Remove any Whitespace and Comment tokens from the list.
type TokensIter ¶ added in v0.0.10
type TokensIter struct {
// contains filtered or unexported fields
}
func NewIter ¶ added in v0.0.10
func NewIter(tokens []Token) *TokensIter
func (TokensIter) HasNext ¶ added in v0.0.10
func (it TokensIter) HasNext() bool
func (*TokensIter) Next ¶ added in v0.0.10
func (it *TokensIter) Next() (t Token)
Next returns the Next token or nil at the end
func (*TokensIter) NextSignificant ¶ added in v0.0.10
func (it *TokensIter) NextSignificant() Token
NextSignificant returns the next significant (neither whitespace or comment) token, or nil
type UnicodeRange ¶ added in v0.0.10
type UnicodeRange struct {
Start, End uint32
// contains filtered or unexported fields
}
func (UnicodeRange) Kind ¶ added in v0.0.10
func (UnicodeRange) Kind() Kind
func (UnicodeRange) Pos ¶ added in v0.0.10
func (v UnicodeRange) Pos() Pos
type Whitespace ¶ added in v0.0.10
type Whitespace struct {
// contains filtered or unexported fields
}
func NewWhitespace ¶ added in v0.0.10
func NewWhitespace(v string, pos Pos) Whitespace
func (Whitespace) Kind ¶ added in v0.0.10
func (Whitespace) Kind() Kind
func (Whitespace) Pos ¶ added in v0.0.10
func (v Whitespace) Pos() Pos