Documentation ¶
Overview ¶
Package css - parse CSS
DESCRIPTION ¶
`css` is a library offering basic CSS parsing. CSS support is minimal enough to support github.com/pirmd/libro needs, essentially identifying possible CSS security issues based on a CSS white-list approach.
`css` is based on github.com/gorilla/css CSS scanner.
Even though, I've tried hard enough to stick to CSS standard and detecting possible CSS syntax issues, it is not a target at this time. You'd probably better go with github.com/aymerick/douceur/. Several test cases are borrowed for its implementation so `css` might be close in term of parsing "correctness". Besides implementation choices and type format, main difference lies in the fact that `css` kept github.com/gorilla/css tokens when describing CSS Rules for easier rules inspection.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Declaration ¶
type Declaration struct { // Property is the style property's name. Property string // Value is the style property's value as a list of token. Value Value // IsImportant is true if the property is tagged as '!important'. IsImportant bool // contains filtered or unexported fields }
Declaration represents a style definition.
func (*Declaration) AppendToValue ¶
func (d *Declaration) AppendToValue(tok *scanner.Token) error
AppendToValue adds a new token to a property. It makes sure that '!important' tag are captured.
func (*Declaration) String ¶
func (d *Declaration) String() string
type Rule ¶
type Rule struct { // Selectors contains the list of tokens of pre-Block declaration that is to say: // - list of selectors for qualified rules, // - list of at-rule specific properties (anything before a ';' or '{'), // Selectors are split during parsing operation using ',' as separator, Selectors []Value // Declarations contains the list of style declarations for the given Rule. Declarations []*Declaration // AtKeyword is the at-keyword introducing teh Rule. If the Rule is a // qualified rule, AtKeyword is nil. AtKeyword *scanner.Token // EmbeddedRuleset contains the nested rules for at-rules that expects it, // otherwise is nil. EmbeddedRuleset Ruleset }
Rule represents a CSS rule
type Ruleset ¶
type Ruleset []*Rule
Ruleset represents a series of rules. NOTA: Ruleset is slightly different from https://www.w3.org/People/howcome/foo.dir/grammar.html definition as it extend the notion to also capture at-rules nested rules.
func ParseInline ¶
ParseInline parses inline CSS text for its list of Rules.
type Value ¶
Value represents a tokenized element (without comments).
func (Value) Scrub ¶
Scrub is called once all token have been scanned for a given Value so that the Value's content is cleaned from:
- Trailing or Tailing token of type scanner.TokenS;
- Token of type scanner.TokenComment;
- "inline" comments are detected and Value is rescanned without them to address of tricky injections like "expr/*XSS*/ession(alert('XSS'))".