Help us shape the future of Go! Take the 2026 Go Developer Survey

css

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2021 License: MIT Imports: 4 Imported by: 0

README

css

Package css is for parsing css stylesheet.

Document

GoDoc

example

import (
	"github.com/vanng822/css"
	"fmt"
)
func main() {
	csstext := "td {width: 100px; height: 100px;}"
	ss := css.Parse(csstext)
	rules := ss.GetCSSRuleList()
	for _, rule := range rules {
		fmt.Println(rule.Style.Selector.Text())
		fmt.Println(rule.Style.Styles)
	}
}

Documentation

Overview

Package css is for parsing css stylesheet.

import (
	"github.com/vanng822/css"
	"fmt"
)
func main() {
	csstext = "td {width: 100px; height: 100px;}"
	ss := css.Parse(csstext)
	rules := ss.GetCSSRuleList()
	for _, rule := range rules {
		fmt.Println(rule.Style.Selector.Text())
		fmt.Println(rule.Style.Styles)
	}
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CSSRule

type CSSRule struct {
	Type  RuleType
	Style CSSStyleRule
	Rules []*CSSRule
}

func NewRule

func NewRule(ruleType RuleType) *CSSRule

type CSSStyleDeclaration

type CSSStyleDeclaration struct {
	Property  string
	Value     *CSSValue
	Important bool
}

func NewCSSStyleDeclaration

func NewCSSStyleDeclaration(property, value string, important bool) *CSSStyleDeclaration

func ParseBlock

func ParseBlock(csstext string) []*CSSStyleDeclaration

ParseBlock take a string of a css block, parses it and returns a map of css style declarations.

func (*CSSStyleDeclaration) Text

func (decl *CSSStyleDeclaration) Text() string

type CSSStyleRule

type CSSStyleRule struct {
	Selector *CSSValue
	Styles   []*CSSStyleDeclaration
}

func (*CSSStyleRule) Text

func (sr *CSSStyleRule) Text() string

type CSSStyleSheet

type CSSStyleSheet struct {
	Type        string
	Media       string
	CssRuleList []*CSSRule
}

func Parse

func Parse(csstext string) *CSSStyleSheet

Parse takes a string of valid css rules, stylesheet, and parses it. Be aware this function has poor error handling so you should have valid syntax in your css

func (*CSSStyleSheet) GetCSSRuleList

func (ss *CSSStyleSheet) GetCSSRuleList() []*CSSRule

type CSSValue added in v1.0.0

type CSSValue struct {
	Tokens []*scanner.Token
}

func NewCSSValue added in v1.0.0

func NewCSSValue(csstext string) *CSSValue

func NewCSSValueString added in v1.0.0

func NewCSSValueString(data string) *CSSValue

func (*CSSValue) ParsedText added in v1.0.0

func (v *CSSValue) ParsedText() string

func (*CSSValue) SplitOnToken added in v1.0.0

func (v *CSSValue) SplitOnToken(split *scanner.Token) []*CSSValue

func (*CSSValue) Text added in v1.0.0

func (v *CSSValue) Text() string

type RuleType

type RuleType int
const (
	STYLE_RULE RuleType = iota
	CHARSET_RULE
	IMPORT_RULE
	MEDIA_RULE
	FONT_FACE_RULE
	PAGE_RULE
	KEYFRAMES_RULE
	WEBKIT_KEYFRAMES_RULE
	COUNTER_STYLE_RULE
)

func (RuleType) Text

func (rt RuleType) Text() string

type State

type State int
const (
	STATE_NONE State = iota
	STATE_SELECTOR
	STATE_PROPERTY
	STATE_VALUE
)

Jump to

Keyboard shortcuts

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