css

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: BSD-3-Clause Imports: 1 Imported by: 0

Documentation

Overview

Package css is the small CSS tree Marpit's theme pipeline needs: rules, at-rules, declarations and comments, parsed leniently, rewritten, and written back out. It plays the part postcss plays in Marpit; it is not a validating parser, and keeps what it does not understand as written.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasNesting

func HasNesting(nodes []Node) bool

HasNesting reports whether any rule holds a rule.

func JoinSelectors

func JoinSelectors(sels []string) string

JoinSelectors joins a selector list.

func SplitSelectors

func SplitSelectors(sel string) []string

SplitSelectors splits a selector list at its top-level commas.

func Walk

func Walk(nodes []Node, fn func(n Node, parent Node) bool)

Walk calls fn for every node, depth first; fn returns false to skip a node's children.

Types

type AtRule

type AtRule struct {
	Name, Params string
	Nodes        []Node
	Block        bool
}

AtRule is an at-rule; Nodes is nil for a statement (@import ...;) and non-nil, possibly empty, for a block.

type Comment

type Comment struct{ Text string }

Comment is a /* comment */; Text excludes the delimiters.

type Decl

type Decl struct {
	Prop, Value string
	Important   bool
}

Decl is a declaration.

type Node

type Node interface {
	// contains filtered or unexported methods
}

Node is a Comment, a Decl, a Rule or an AtRule.

func Flatten

func Flatten(nodes []Node) []Node

Flatten resolves CSS nesting: a rule nested in a rule becomes a sibling whose selector combines both, and a conditional at-rule nested in a rule wraps a copy of the parent rule.

Marpit runs postcss-nesting, then turns the :is() it produces back into plain selectors when they start from section or :root, so that its later prefixing sees a section. Expanding every parent/child combination gives those plain selectors directly.

type Rule

type Rule struct {
	Selector string
	Nodes    []Node
}

Rule is a style rule.

type Sheet

type Sheet struct{ Nodes []Node }

Sheet is a parsed style sheet.

func Parse

func Parse(src string) *Sheet

Parse parses a style sheet.

func (*Sheet) String

func (s *Sheet) String() string

String writes the sheet out.

Jump to

Keyboard shortcuts

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