Skip to content

matthewmueller/css

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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