Skip to content

Latest commit

 

History

History
50 lines (34 loc) · 1.24 KB

README.md

File metadata and controls

50 lines (34 loc) · 1.24 KB

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.