You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The ParserLib CSS parser is a CSS3 SAX-inspired parser written in JavaScript. By default, the parser only deals with standard CSS syntax and doesn't do validation (checking of property names and values).
10
8
11
-
Adding to your project
12
-
----------------------
9
+
## Adding to your project
13
10
14
11
The CSS parser is intended for use primarily in command line JavaScript environments. The files you should use are in the `build` directory. Copy the files to an appropriate location for your usage.
15
12
@@ -40,8 +37,7 @@ Or include it as its component parts, the ParserLib core and the CSS parser:
40
37
```
41
38
Note that parsing large JavaScript files may cause the browser to become unresponsive.
42
39
43
-
Basic usage
44
-
-----------
40
+
## Basic usage
45
41
46
42
You can create a new instance of the parser by using the following code:
47
43
```js
@@ -66,8 +62,7 @@ The `parse()` method throws an error if a non-recoverable syntax error occurs, o
66
62
67
63
Note: The `parseStyleSheet()` method is provided for compatibility with SAC-based APIs but does the exact same thing as `parse()`.
68
64
69
-
Understanding syntax units
70
-
--------------------------
65
+
## Understanding syntax units
71
66
72
67
The CSS parser defines several types that inherit from `parserlib.util.SyntaxUnit`. These types are designed to give you easy access to all relevant parts of the CSS syntax.
73
68
@@ -131,16 +126,15 @@ Each instance of `parserlib.css.SelectorPart` has an `elementName` property, whi
131
126
Each instance of `parserlib.css.Combinator` has an additional `type` property that indicates the type of combinator: "descendant", "child", "sibling", or "adjacent-sibling".
132
127
133
128
134
-
Using events
135
-
------------
129
+
## Using events
136
130
137
131
The CSS parser fires events as it parses text. The events correspond to important parts of the parsing algorithm and are designed to provide developers with all of the information necessary to create lint checkers, ASTs, and other data structures.
138
132
139
133
For many events, the `event` object contains additional information. This additional information is most frequently in the form of a `parserlib.util.SyntaxUnit` object, which has three properties:
140
134
141
135
1. `text` - the string value
142
-
1. `line` - the line on which this token appeared
143
-
1. `col` - the column within the line at which this token appeared
136
+
2. `line` - the line on which this token appeared
137
+
3. `col` - the column within the line at which this token appeared
144
138
145
139
The `toString()` method for these objects is overridden to be the same value as `text`, so that you can treat the object as a string for comparison and concatenation purposes.
The CSS parser's goal is to be on-par with error recovery of CSS parsers in browsers. To that end, the following error recovery mechanisms are in place:
300
294
@@ -318,7 +312,6 @@ a:hover, foo ... bar {
318
312
319
313
***Unknown @ Rules** - any @ rules that isn't recognized is automatically skipped, meaning the entire block after it is not parsed.
320
314
321
-
Running Tests
322
-
-------------
315
+
## Running Tests
323
316
324
317
With the Apache Ant build tool installed, you can run the tests via `ant test` from the repository's root.
0 commit comments