https://github.com/napsy/go-css
A very simple CSS parser, written in Go
https://github.com/napsy/go-css
css golang
Last synced: 7 months ago
JSON representation
A very simple CSS parser, written in Go
- Host: GitHub
- URL: https://github.com/napsy/go-css
- Owner: napsy
- License: bsd-3-clause
- Created: 2017-07-25T19:28:39.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-06-11T14:29:00.000Z (over 2 years ago)
- Last Synced: 2025-03-23T00:06:48.708Z (8 months ago)
- Topics: css, golang
- Language: Go
- Homepage:
- Size: 27.3 KB
- Stars: 79
- Watchers: 2
- Forks: 9
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - napsy/go-css
- awesome-go - napsy/go-css
- awesome-go - go-css - A very simple CSS parser, written in Go. (CSS Preprocessors / Standard CLI)
- fucking-awesome-go - go-css - A very simple CSS parser, written in Go. (CSS Preprocessors / Standard CLI)
- awesome-go - go-css - A very simple CSS parser, written in Go. (CSS Preprocessors / Standard CLI)
- awesome-go-with-stars - go-css - A very simple CSS parser, written in Go. (CSS Preprocessors / Standard CLI)
README
# go-css
[](https://travis-ci.org/napsy/go-css)
[](https://github.com/vendor/package/blob/master/LICENSE.md)
[](https://godoc.org/github.com/napsy/go-css)
This parser understands simple CSS and comes with a basic CSS syntax checker.
```
go get github.com/napsy/go-css
```
Example usage:
```go
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``:
```go
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.