CSSTree
Fast detailed CSS parser
Work in progress. Project in alpha stage since AST format is subject to change.
Docs and tools:
- AST Explorer – explore CSSTree AST format with zero setup
- CSS syntax reference
- CSS syntax validator
Related projects:
- csstree-validator – NPM package to validate CSS
- stylelint-csstree-validator – plugin for stylelint to validate CSS
- Grunt plugin
- Gulp plugin
- Sublime plugin
- VS Code plugin
- Atom plugin
Install
> npm install css-tree
Usage
var csstree = require('css-tree');
var ast = csstree.parse('.example { world: "!" }');
csstree.walk(ast, function(node) {
if (node.type === 'ClassSelector' && node.name === 'example') {
node.name = 'hello';
}
});
console.log(csstree.translate(ast));
// .hello{world:"!"}
License
MIT
Syntax matching use mdn/data by Mozilla Contributors