Documentation
¶
Overview ¶
Package css handles CSS Syntax Module Level 3.
Parts of the documentation are copied from the specification, see the W3 Document License for details.
Overview ¶
- Use ParseDeclarationList for parsing a style attribute.
- Use ParseStylesheet for parsing a stylesheet.
- Use Scanner for CSS tokenization.
Index ¶
Constants ¶
const ( IDENT = iota + 0xe000 // <ident-token> FUNCTION // <function-token> AT_KEYWORD // <at-keyword-token> HASH // <hash-token> STRING // <string-token> BAD_STRING // <bad-string-token> URL // <url-token> BAD_URL // <bad-url-token> DELIM // <delim-token> NUMBER // <number-token> PERCENTAGE // <percentage-token> DIMENSION // <dimension-token> WHITESPACE // <whitespace-token> CDO // <CDO-token> CDC // <CDC-token> COLON // <colon-token> SEMICOLON // <semicolon-token> COMMA // <comma-token> LBRACKET // <[-token> RBRACKET // <]-token> LPAREN // <(-token> RPAREN // <)-token> LBRACE // <{-token> RBRACE // <}-token> EOF // <EOF-token> )
Values of tokens defined in the relevant specification part.
Variables ¶
This section is empty.
Functions ¶
func Preprocess ¶
Preprocess implements CSS input preprocessing. The backing array of 'buf' is not mutated, 'r' is newly allocated.
Types ¶
type AtRule ¶ added in v0.0.2
type AtRule struct { Name string Prelude Components Block *SimpleBlock }
An AtRule has a name, a prelude consisting of a list of component values, and an optional block consisting of a simple {} block.
Note: The specification places no limits on what an at-rule’s block may contain. Individual at-rules must define whether they accept a block, and if so, how to parse it (preferably using one of the parser algorithms or entry points defined in this specification).
type Component ¶ added in v0.0.2
type Component interface { Node }
A Component is one of the preserved tokens, a function, or a simple block.
type Components ¶ added in v0.1.0
type Components []Component
Components type represents a slice of Component items.
func (Components) Position ¶ added in v0.1.0
func (n Components) Position() (r token.Position)
Position implements Node.
func (Components) String ¶ added in v0.1.0
func (n Components) String() string
String implements Node.
type Declaration ¶ added in v0.0.2
type Declaration struct { Name string Value Components Important bool // contains filtered or unexported fields }
Declaration lists are produced by ParseDeclarationList.
Conceptually, declarations are a particular instance of associating a property or descriptor name with a value. Syntactically, a declaration has a name, a value consisting of a list of component values, and an important flag which is initially unset.
Declarations are further categorized as property declarations or descriptor declarations, with the former setting CSS properties and appearing most often in qualified rules and the latter setting CSS descriptors, which appear only in at-rules. (This categorization does not occur at the Syntax level; instead, it is a product of where the declaration appears, and is defined by the respective specifications defining the given rule.)
func (*Declaration) Position ¶ added in v0.0.2
func (n *Declaration) Position() (r token.Position)
Position implements Node.
func (*Declaration) String ¶ added in v0.1.0
func (n *Declaration) String() string
String implements Node.
type Function ¶ added in v0.0.2
type Function struct { Name string Components Components // contains filtered or unexported fields }
A Function has a name and a value consisting of a list of component values.
type Nodes ¶ added in v0.1.0
type Nodes []Node
Components type represents a slice of Node items.
func ParseDeclarationList ¶ added in v0.0.2
ParseDeclarationList is for the contents of a style attribute, which parses text into the contents of a single style rule.
ParseDeclarationList implements 5.3.8. Parse a list of declarations with the following deviations.
- Source in 'buf' is not input-preprocessed. There's a separate Preprocess function available available for that, but the parser handles both preprocessed and not preprocessed sources.
The 'name' argument is used to report positions. 'buf' becomes owned by the 'ast' node and should not be mutated by the caller afterwards.
type QualifiedRule ¶ added in v0.0.2
type QualifiedRule struct { Prelude Components Block *SimpleBlock }
QualifiedRule represents a qualified CSS rule.
A qualified rule has a prelude consisting of a list of component values, and a block consisting of a simple {} block.
Note: Most qualified rules will be style rules, where the prelude is a selector and the block a list of declarations.
func (*QualifiedRule) Position ¶ added in v0.0.2
func (n *QualifiedRule) Position() (r token.Position)
Position implements Node.
func (*QualifiedRule) String ¶ added in v0.1.0
func (n *QualifiedRule) String() string
String implements Node.
type Rule ¶ added in v0.0.2
type Rule interface { Node }
Rule is either a *QualifiedRule or an *AtRule.
type Rules ¶ added in v0.1.0
type Rules []Rule
Rules type represents a slice of Rule items.
type Scanner ¶
Scanner implements this CSS3 Tokenization specification with the following deviations.
- Source in 'buf' is not input-preprocessed. The scanner is modified to handle sources that are not preprocessed. There's a separate Preprocess function available.
- Surrogates (U+D800 to U+DFFF inclusive) are not replaced by the replacement character (U+FFFD).
func NewScanner ¶
NewScanner returns a newly created Scanner. The 'name' argument is used to report positions. 'buf' becomes owned by the scanner and should not be mutated by the caller afterwards.
Use the promoted methods of scanner.Scanner to do some actual work.
Use the scanner.Err function to check for scanning errors.
type SimpleBlock ¶ added in v0.0.2
type SimpleBlock struct { Components Components Open string // "{" or "[" or "(" // contains filtered or unexported fields }
SimpleBlock has an associated token (either a <[-token>, <(-token>, or <{-token>) and a value consisting of a list of component values.
func (*SimpleBlock) Position ¶ added in v0.0.2
func (s *SimpleBlock) Position() (r token.Position)
Position implements Node.
func (*SimpleBlock) String ¶ added in v0.1.0
func (n *SimpleBlock) String() string
String implements Node.
type Stylesheet ¶ added in v0.0.2
Stylesheet represents a CSS stylesheet.
func ParseStylesheet ¶ added in v0.0.2
func ParseStylesheet(name, url string, buf []byte) (r *Stylesheet, err error)
ParseStylesheet is intended to be the normal parser entry point, for parsing stylesheets.
ParseStylesheet implements 5.3.3 Parse a stylesheet with the following deviations.
- Source in 'buf' is not input-preprocessed. There's a separate Preprocess function available available for that, but the parser handles both preprocessed and not preprocessed sources.
The 'name' argument is used to report positions. 'buf' becomes owned by the 'ast' node and should not be mutated by the caller afterwards.
func (*Stylesheet) Position ¶ added in v0.1.0
func (n *Stylesheet) Position() (r token.Position)
Position implements Node.
func (*Stylesheet) String ¶ added in v0.1.0
func (n *Stylesheet) String() string
String implements Node.