A non-validating CSS parser with comment support and flexible AST representation.
Mensch is a CSS parser for Node.js that converts CSS strings into abstract syntax trees (ASTs) and back. It focuses on handling major language constructs while recovering from common syntax errors like mismatched braces and missing semicolons. The parser is non-validating, meaning it does not check for invalid property names or rule placement.
Node.js developers who need to parse, manipulate, or analyze CSS programmatically, such as those building CSS preprocessors, linters, or email template editors. It is also suitable for projects requiring robust error recovery and comment preservation in CSS processing.
Developers choose Mensch for its graceful error recovery from syntax errors and its ability to preserve comments in the AST—a feature uncommon in most CSS parsers. It also provides lexical tokenization and position tracking for advanced use cases.
A decent CSS parser.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Handles common syntax errors like mismatched braces and missing semicolons without crashing, as emphasized in the non-validating parsing philosophy.
When enabled via options, preserves comments in the AST and stringified output—a feature the README notes is uncommon in most CSS parsers.
Optional line and column position inclusion in AST nodes supports error reporting and debugging for tools like linters or analyzers.
Provides a separate lex() function to convert CSS to tokens for advanced use cases, such as custom parsing or syntax highlighting.
As a non-validating parser, it cannot detect invalid CSS like misspelled property names or misplaced rules, limiting its use for validation-heavy tasks.
Comments within selectors, properties, or other contexts are ignored and not preserved in the AST, as admitted in the README's examples.
The AST structure is not guaranteed to be 100% compatible with other CSS parsers, which could cause interoperability issues in multi-tool environments.