Documentation
¶
Overview ¶
Package `cssparser` provides a parser for CSS (Cascading Style Sheets) files.
It allows parsing of stylesheets and declarations, handling both inline and embedded styles.
For example, you can use it to parse a CSS stylesheet and retrieve its rules or declarations.
Here's a brief overview of the main functions: - ParseStylesheet(content string) (*Stylesheet, error): Parses a complete CSS stylesheet. - ParseDeclarations(content string) ([]*Declaration, error): Parses CSS declarations, typically used for inline styles.
The source code of this package is hosted on GitHub: https://github.com/renbaoshuo/go-css-parser
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CssRule ¶
type CssRule struct {
Kind CssRuleKind
Name string // At Rule name (eg: "@media")
Prelude string // Raw prelude: https://github.com/csstree/csstree/discussions/168
Selectors []string // Qualified Rule selectors parsed from prelude
Declarations []*Declaration // Style properties
Rules []*CssRule // At Rule embedded rules
EmbedLevel int // Current rule embedding level
}
func NewCssRule ¶
func NewCssRule(kind CssRuleKind) *CssRule
type CssRuleKind ¶
type CssRuleKind int
const ( QualifiedRule CssRuleKind = iota AtRule )
func (CssRuleKind) String ¶
func (k CssRuleKind) String() string
type Declaration ¶ added in v0.0.6
func NewCssDeclaration ¶
func NewCssDeclaration() *Declaration
func ParseDeclarations ¶
func ParseDeclarations(content string) ([]*Declaration, error)
func (*Declaration) Equal ¶ added in v0.0.6
func (d *Declaration) Equal(other *Declaration) bool
func (*Declaration) String ¶ added in v0.0.6
func (d *Declaration) String() string
func (*Declaration) StringWithImportant ¶ added in v0.0.6
func (d *Declaration) StringWithImportant(option bool) string
func (*Declaration) ValueString ¶ added in v0.0.6
func (d *Declaration) ValueString() string
func (*Declaration) ValueStringWithImportant ¶ added in v0.0.6
func (d *Declaration) ValueStringWithImportant(option bool) string
type DeclarationsByProperty ¶
type DeclarationsByProperty []*Declaration
func (DeclarationsByProperty) Len ¶
func (ds DeclarationsByProperty) Len() int
Implements sort.Interface
func (DeclarationsByProperty) Less ¶
func (ds DeclarationsByProperty) Less(i, j int) bool
func (DeclarationsByProperty) Swap ¶
func (ds DeclarationsByProperty) Swap(i, j int)
func (DeclarationsByProperty) ToObject ¶ added in v0.0.5
func (ds DeclarationsByProperty) ToObject() map[string]string
ToObject converts DeclarationsByProperty to a map[string]string
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
func (*Parser) ParseDeclarations ¶
func (p *Parser) ParseDeclarations() ([]*Declaration, error)
func (*Parser) ParseStylesheet ¶
func (p *Parser) ParseStylesheet() (*Stylesheet, error)
type Stylesheet ¶ added in v0.0.6
type Stylesheet struct {
Rules []*CssRule
}
func NewStylesheet ¶ added in v0.0.6
func NewStylesheet() *Stylesheet
func ParseStylesheet ¶
func ParseStylesheet(content string) (*Stylesheet, error)
func (*Stylesheet) String ¶ added in v0.0.6
func (s *Stylesheet) String() string
Source Files
¶
- css_declaration.go
- css_rule.go
- css_stylesheet.go
- doc.go
- parser.go
- parser_base.go
- parser_util.go