Skip to content

Repository files navigation

CSS selectors in Go

Go Reference

This package implements a CSS selector compiler for Go's HTML parsing package golang.org/x/net/html.

package main
import (
"fmt""os""strings""github.com/ericchiang/css""golang.org/x/net/html"
)
vardata=`<p> <h2 id="foo">a header</h2> <h2 id="bar">another header</h2></p>`funcmain() {
sel, err:=css.Parse("h2#foo")
iferr!=nil {
panic(err)
}
node, err:=html.Parse(strings.NewReader(data))
iferr!=nil {
panic(err)
}
for_, ele:=rangesel.Select(node) {
html.Render(os.Stdout, ele)
}
fmt.Println()
}
$ go run example/css.go
<h2 id="foo">a header</h2>

About

CSS Selectors for Go

Resources

Security policy

Stars

137 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages