CSS lexer and parser for Go. Intended to be used for manipulating stylesheets.
Fully parses Bootstrap 5 and several other popular CSS frameworks and website stylesheets.
input := `@media screen and (min-width: 480px) {
body {
background-color: lightgreen;
}
}
`
ast, _ := css.Parse("input.css", input)
fmt.Println(ast.String())
This package supports scoping CSS with a selector
input := `a:hover, span, .c, :global(#d) {
color: red;
}`
scoped, err := scoper.Scope("input.css", ".scoped", input)
// a.scoped:hover, span.scoped, .c.scoped, #d { color: red }
- Parse Bootstrap 4
- Nested
&
support
- tdewolfe/parse: Most popular. Low-level streaming grammar makes writing codemods difficult. Doesn't parse selectors. Looks primarily intended for fast minification.
- benpjohnson/css: Almost what we want. Doesn't parse selectors. Hasn't been updated in 10 years.
- gorilla/css: Just a scanner, there's no parser.
- matthewmueller/jsx: JSX parser
MIT