cssparse

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2026 License: MIT Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package cssparse provides the small, bounded CSS rule/declaration parser shared by Paper's HTML and SVG renderers. It intentionally models the stylesheet surface Paper consumes instead of attempting browser-complete CSS.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SplitSelectors

func SplitSelectors(value string) []string

SplitSelectors splits a selector list on only top-level commas. It keeps selector text (including escapes and function/attribute contents) intact.

func StripImportantSuffix

func StripImportantSuffix(value string) (string, bool)

StripImportantSuffix removes a trailing `!important` from a declaration value. It reports whether the suffix was there.

Types

type Declaration

type Declaration struct {
	Property  string
	Value     string
	Important bool
}

Declaration is one `property: value` pair, and whether it ended in `!important`.

type Rule

type Rule struct {
	Kind         RuleKind
	Name         string
	Prelude      string
	Selectors    []string
	Declarations []Declaration
	Rules        []*Rule
}

Rule is a parsed CSS rule. A qualified rule uses Selectors and Declarations; an at-rule uses Name and Prelude, and may nest further Rules.

func Parse

func Parse(text string) ([]*Rule, error)

Parse parses a stylesheet with no cap on the number of rules.

func ParseWithMaxRules

func ParseWithMaxRules(text string, maxRules int) ([]*Rule, error)

ParseWithMaxRules parses a stylesheet and fails once it has read more than maxRules rules. A maxRules of zero or less means no cap.

type RuleKind

type RuleKind uint8

RuleKind tells a Rule apart: a normal selector rule or an at-rule.

const (
	QualifiedRule RuleKind = iota
	AtRule
)

QualifiedRule is a selector rule such as `p { color: red }`. AtRule is a rule introduced by an at-keyword, such as `@media`.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL