css

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 5, 2025 License: BSD-3-Clause Imports: 12 Imported by: 1

README

logo

Go Reference

LiberaPay receives patrons

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

Index

Constants

View Source
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

func Preprocess(buf []byte) (r []byte)

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).

func (*AtRule) Position added in v0.0.2

func (n *AtRule) Position() (r token.Position)

Position implements Node.

func (*AtRule) String added in v0.1.0

func (n *AtRule) String() string

String implements Node.

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.

func (*Function) Position added in v0.0.2

func (s *Function) Position() (r token.Position)

Position implements Node.

func (*Function) String added in v0.1.0

func (n *Function) String() string

String implements Node.

type Node added in v0.0.2

type Node interface {
	Position() token.Position
	String() string
}

Node is implemented by items produced by the parser.

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

func ParseDeclarationList(name string, buf []byte) (r Nodes, err error)

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.

func (Nodes) Position added in v0.1.0

func (n Nodes) Position() (r token.Position)

Position implements Node.

func (Nodes) String added in v0.1.0

func (n Nodes) String() string

String implements Node.

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.

func (Rules) Position added in v0.1.0

func (n Rules) Position() (r token.Position)

Position implements Node.

func (Rules) String added in v0.1.0

func (n Rules) String() string

String implements Node.

type Scanner

type Scanner struct {
	*scanner.Scanner
	// contains filtered or unexported fields
}

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

func NewScanner(name string, buf []byte) (r *Scanner)

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.

func (*Scanner) Scan added in v0.0.2

func (s *Scanner) Scan() (r scanner.Token)

Scan returns the next token.

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

type Stylesheet struct {
	Location string
	Rules    Rules
}

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.

Jump to

Keyboard shortcuts

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