rust-css-parser
A fault-tolerant CSS parser, validator, minifier and renderer: the Rust port of @tbela99/css-parser. The module tree mirrors the TypeScript sources and the functions keep their names in snake case.
- parse, minify and render CSS, with source maps
- syntax validation of the declarations, at-rules and selectors
- CSS nesting,
calc()evaluation, color conversion (rgb(),oklch(),color-mix(), ...), shorthand computation - CSS modules
The same library is available for JavaScript: @tbela99/rust-css-parser-napi (Node.js, N-API) and @tbela99/rust-css-parser-wasm (Node.js and the browsers, WebAssembly).
Usage
[]
= "2"
use NoHost;
use ;
use CssInput;
use do_parse_sync;
use SourceFile;
use ;
use do_render;
use Rc;
let css = ".a { color: rgb(255 0 0); width: calc(1px + 2px) } .b { color: red }";
// the source file: the locations, the source maps and the string table refer to it
let source = new;
let sources = default;
sources.borrow_mut.insert;
let options = ParserOptions ;
let tokenizer = new;
// NoHost: no callbacks (visitors, load(), ...)
let result = do_parse_sync.expect;
let rendered = do_render;
assert_eq!;
See the Rust API guide and the API reference.