matthewmueller / css

CSS lexer and parser for Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

css

Go Reference

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.

Usage

input := `@media screen and (min-width: 480px) {
  body {
    background-color: lightgreen;
  }
}
`
ast, _ := css.Parse("input.css", input)
fmt.Println(ast.String())

Scoping

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 }

Planned

  • Parse Bootstrap 4
  • Nested & support

Similar

  • 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.

Related

License

MIT

About

CSS lexer and parser for Go

License:MIT License


Languages

Language:Go 99.4%Language:Makefile 0.6%