Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ericchiang/css
CSS Selectors for Go
https://github.com/ericchiang/css
Last synced: 7 days ago
JSON representation
CSS Selectors for Go
- Host: GitHub
- URL: https://github.com/ericchiang/css
- Owner: ericchiang
- License: mit
- Created: 2015-12-14T00:30:52.000Z (almost 9 years ago)
- Default Branch: main
- Last Pushed: 2024-08-17T17:54:42.000Z (3 months ago)
- Last Synced: 2024-10-14T16:33:11.689Z (25 days ago)
- Language: Go
- Homepage:
- Size: 68.4 KB
- Stars: 132
- Watchers: 4
- Forks: 17
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- go-awesome - css - CSS selectors (Open source library / Word Processing)
README
# CSS selectors in Go
[![Go Reference](https://pkg.go.dev/badge/github.com/ericchiang/css.svg)](https://pkg.go.dev/github.com/ericchiang/css)
This package implements a CSS selector compiler for Go's HTML parsing package golang.org/x/net/html.
```go
package mainimport (
"fmt"
"os"
"strings""github.com/ericchiang/css"
"golang.org/x/net/html"
)var data = `
a header
another header
`func main() {
sel, err := css.Parse("h2#foo")
if err != nil {
panic(err)
}
node, err := html.Parse(strings.NewReader(data))
if err != nil {
panic(err)
}
for _, ele := range sel.Select(node) {
html.Render(os.Stdout, ele)
}
fmt.Println()
}
``````
$ go run example/css.goa header
```