go-css
A very simple CSS parser, written in Go
About go-css
go-css
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.
Frequently Asked Questions
What is go-css?
go-css is a CSS Preprocessors library for the Go programming language. A very simple CSS parser, written in Go
How do I install go-css?
Install go-css with the Go module system using `go get napsy/go-css`. Check the repository for the current installation instructions.
What category does go-css belong to?
go-css is listed under CSS Preprocessors, specifically CSS Preprocessors.