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
Copy file name to clipboardExpand all lines: README.md
+18-18Lines changed: 18 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ To use the CSS parser in a Node.js script, include it at the beginning:
19
19
```js
20
20
var parserlib =require("./node-parserlib");
21
21
```
22
-
22
+
23
23
### Rhino
24
24
25
25
To use the CSS parser in a Rhino script, include it at the beginning:
@@ -32,7 +32,7 @@ load("parserlib.js");
32
32
To use the CSS parser on an HTML page, you can either include the entire library on your page:
33
33
```html
34
34
<scriptsrc="parserlib.js"></script>
35
-
```
35
+
```
36
36
Or include it as its component parts, the ParserLib core and the CSS parser:
37
37
```html
38
38
<scriptsrc="parserlib-core.js"></script>
@@ -46,7 +46,7 @@ Basic usage
46
46
You can create a new instance of the parser by using the following code:
47
47
```js
48
48
var parser =newparserlib.css.Parser();
49
-
```
49
+
```
50
50
The constructor accepts an options object that specifies additional features the parser should use. The available options are:
51
51
52
52
*`starHack` - set to true to treat properties with a leading asterisk as if the asterisk wasn't there. Default is false.
@@ -61,7 +61,7 @@ var parser = new parserlib.css.Parser({ starHack: true, underscoreHack: true });
61
61
You can then parse a string of CSS code by passing into the `parse()` method:
62
62
```js
63
63
parser.parse(someCSSText);
64
-
```
64
+
```
65
65
The `parse()` method throws an error if a non-recoverable syntax error occurs, otherwise it finishes silently. This method does not return a value nor does it build up an abstract syntax tree (AST) for you, it simply parses the CSS text and fires events at important moments along the parse.
66
66
67
67
Note: The `parseStyleSheet()` method is provided for compatibility with SAC-based APIs but does the exact same thing as `parse()`.
@@ -87,7 +87,7 @@ The `parserlib.css.MediaQuery` type represents all parts of a media query. Each
87
87
For example, consider the following media query:
88
88
```css
89
89
only screen and (max-device-width: 768px) and (orientation:portrait)
90
-
```
90
+
```
91
91
A corresponding object would have the following values:
92
92
93
93
*`modifier` = "only"
@@ -126,7 +126,7 @@ li.selected > a:hover
126
126
```
127
127
This selector has three parts: `li.selected`, `>`, and `a:hover`. The first part is a `SelectorPart`, the second is a `Combinator`, and the third is a `SelectorPart`. Each `SelectorPart` is made up of an optional element name followed by an ID, class, attribute condition, pseudo class, and/or pseudo element.
128
128
129
-
Each instance of `parserlib.css.SelectorPart` has an `elementName` property, which represents the element name as a `parserlib.css.SelectorSubPart` object or `null` if there isn't one, and a `modifiers` property, which is an array of `parserlib.css.SelectorSubPart` objects. Each `SelectorSubPart` object represents the smallest individual piece of a selector and has a `type` property indicating the type of subpart, "elementName", "class", "attribute", "pseudo", "id", "not". If the `type` is "not", then the `args` property contains an array of `SelectorPart` arguments that were passed to `not()`.
129
+
Each instance of `parserlib.css.SelectorPart` has an `elementName` property, which represents the element name as a `parserlib.css.SelectorSubPart` object or `null` if there isn't one, and a `modifiers` property, which is an array of `parserlib.css.SelectorSubPart` objects. Each `SelectorSubPart` object represents the smallest individual piece of a selector and has a `type` property indicating the type of subpart, "elementName", "class", "attribute", "pseudo", "id", "not". If the `type` is "not", then the `args` property contains an array of `SelectorPart` arguments that were passed to `not()`.
130
130
131
131
Each instance of `parserlib.css.Combinator` has an additional `type` property that indicates the type of combinator: "descendant", "child", "sibling", or "adjacent-sibling".
The `startpage` event fires when `@page` is encountered and the `endfontface` event fires just after the closing right brace (`}`) is encountered after `@page`. The `event` object has two properties: `id`, which is the page ID, and `pseudo`, which is the page pseudo class. Example:
The `startpagemargin` event fires when a page margin directive (such as `@top-left`) is encountered and the `endfontface` event fires just after the closing right brace (`}`) is encountered after the page margin. The `event` object has a `margin` property, which contains the actual page margin encountered. Example:
The `startmedia` event fires when `@media` is encountered and the `endmedia` event fires just after the closing right brace (`}`) is encountered after `@media`. The `event` object has one property, `media`, which is an array of `parserlib.css.MediaQuery` objects. Example:
The `startkeyframes` event fires when `@keyframes` (or any vendor prefixed version) is encountered and the `endkeyframes` event fires just after the closing right brace (`}`) is encountered after `@keyframes`. The `event` object has one property, `name`, which is the name of the animation. Example:
The `startrule` event fires just after all selectors on a rule have been parsed and the `endrule` event fires just after the closing right brace (`}`) is encountered for the rule. The `event` object has one additional property, `selectors`, which is an array of `parserlib.css.Selector` objects. Example:
251
-
```js
249
+
250
+
The `startrule` event fires just after all selectors on a rule have been parsed and the `endrule` event fires just after the closing right brace (`}`) is encountered for the rule. The `event` object has one additional property, `selectors`, which is an array of `parserlib.css.Selector` objects. Example:
251
+
```js
252
252
parser.addListener("startrule", function(event){
253
253
console.log("Starting rule with "+event.selectors.length+" selector(s)");
254
-
254
+
255
255
for (var i=0,len=event.selectors.length; i < len; i++){
0 commit comments