55## Introduction
66
77The ParserLib CSS parser is a CSS3 SAX-inspired parser written in JavaScript.
8- By default, the parser only deals with standard CSS syntax and doesn't do validation (checking of property names and values).
8+ It handles standard CSS syntax as well as validation (checking of
9+ property names and values) although it is not guaranteed to thoroughly
10+ validate all possible CSS properties.
911
1012## Adding to your project
1113
12- The CSS parser is intended for use primarily in command line JavaScript environments.
13- The files you should use are in the ` build ` directory. Copy the files to an appropriate location for your usage.
14+ The CSS parser is built for a number of different JavaScript
15+ environments. The most recently released version of the parser
16+ can be found in the ` dist ` directory when you check out the
17+ repository; run ` npm run build ` to regenerate them from the
18+ latest sources.
1419
1520### Node.js
1621
17- To use the CSS parser in a Node.js script, include it at the beginning:
22+ You can use the CSS parser in a ` Node.js ` script via the standard
23+ ` npm ` package manager as the ` parserlib ` package (` npm install parserlib ` ):
24+
25+ ``` js
26+ var parserlib = require (" parserlib" );
27+
28+ var parser = new parserlib.css.Parser ();
29+ ```
30+
31+ Alternatively, you can copy a single file version of the parser from
32+ ` dist/node-parserlib.js ` to your own project, and use it as follows:
1833``` js
1934var parserlib = require (" ./node-parserlib" );
2035```
2136
2237### Rhino
2338
24- To use the CSS parser in a Rhino script, include it at the beginning:
39+ To use the CSS parser in a Rhino script, copy the file
40+ ` dist/parserlib.js ` to your project and then include it at the beginning:
2541``` js
2642load (" parserlib.js" );
2743```
@@ -37,7 +53,9 @@ Or include it as its component parts, the ParserLib core and the CSS parser:
3753<script src =" parserlib-core.js" ></script >
3854<script src =" parserlib-css.js" ></script >
3955```
40- Note that parsing large JavaScript files may cause the browser to become unresponsive.
56+ Note that parsing large JavaScript files may cause the browser to
57+ become unresponsive. All three of these files are located in the
58+ ` dist ` directory.
4159
4260## Basic usage
4361
@@ -360,11 +378,12 @@ parser.addListener("endrule", function(event) {
360378
361379The ` property ` event fires whenever a CSS property (` name:value ` ) is encountered,
362380which may be inside of a rule, a media block, a page block, etc. The ` event ` object
363- has three additional properties: ` property ` , which is the name of the property as a
381+ has four additional properties: ` property ` , which is the name of the property as a
364382` parserlib.css.PropertyName ` object, ` value ` , which is an instance of
365383` parserlib.css.PropertyValue ` (both types inherit from ` parserlib.util.SyntaxUnit ` ),
366- and ` important ` , which is a Boolean value indicating if the property is flagged
367- with ` !important ` . Example:
384+ ` important ` , which is a Boolean value indicating if the property is flagged
385+ with ` !important ` , and ` invalid ` which is a Boolean value indicating
386+ whether the property value failed validation. Example:
368387
369388``` js
370389parser .addListener (" property" , function (event ) {
@@ -417,4 +436,5 @@ a:hover, foo ... bar {
417436
418437## Running Tests
419438
420- With the Apache Ant build tool installed, you can run the tests via ` ant test ` from the repository's root.
439+ You can run the tests via ` npm test ` from the repository's root. You
440+ may need to run ` npm install ` first to install the necessary dependencies.
0 commit comments