Skip to content

napsy/go-css

Repository files navigation

go-css

Build Status Software License GoDoc

This parser understands simple CSS and comes with a basic CSS syntax checker.

go get github.com/napsy/go-css

Example usage:

import "github.com/napsy/go-css"

ex1 := `rule {
	style1: value1;
	style2: value2;
}`

stylesheet, err := css.Unmarshal([]byte(ex1))
if err != nil {
	panic(err)
}

fmt.Printf("Defined rules:\n")

for k, _ := range stylesheet {
	fmt.Printf("- rule %q\n", k)
}

You can get a CSS verifiable property by calling CSSStyle:

style, err := css.CSSStyle("background-color", styleSheet["body"])
if err != nil {
	fmt.Printf("Error checking body background color: %v\n", err)
} else {
	fmt.Printf("Body background color is %v", style)
}

Most of the CSS properties are currently not implemented, but you can always write your own handler by writing a StyleHandler function and adding it to the StylesTable map.

About

A very simple CSS parser, written in Go

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages