Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ericchiang/css

CSS Selectors for Go
https://github.com/ericchiang/css

Last synced: 8 days ago
JSON representation

CSS Selectors for Go

Awesome Lists containing this project

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 main

import (
"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.go

a header


```