Skip to content

Commit c8e9c29

Browse files
committed
upd Readme
1 parent ca86fba commit c8e9c29

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

README.md

+53
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,59 @@
55

66
Parse HTML/XML to [PostHTMLTree](https://github.com/posthtml/posthtml#posthtml-json-tree-example)
77

8+
## Install
9+
10+
[NPM](http://npmjs.com) install
11+
```
12+
$ npm install posthtml-parser
13+
```
14+
15+
## Usage
16+
17+
#### input HTML
18+
```html
19+
<a class="animals" href="#">
20+
<span class="animals__cat" style="background: url(cat.png)">Cat</span>
21+
</a>
22+
```
23+
```js
24+
var parser = require('posthtml-parser');
25+
var fs = require('fs');
26+
var html = fs.readFileSync('path/to/input.html').toString();
27+
28+
clonsole.log(parser(html)); // Look #Result PostHTMLTree
29+
```
30+
31+
#### input HTML
32+
```html
33+
<a class="animals" href="#">
34+
<span class="animals__cat" style="background: url(cat.png)">Cat</span>
35+
</a>
36+
```
37+
38+
#### Result PostHTMLTree
39+
```js
40+
[{
41+
tag: 'a',
42+
attrs: {
43+
class: 'animals',
44+
href: '#'
45+
},
46+
content: [
47+
'\n ',
48+
{
49+
tag: 'span',
50+
attrs: {
51+
class: 'animals__cat',
52+
style: 'background: url(cat.png)'
53+
},
54+
content: ['Cat']
55+
},
56+
'\n'
57+
]
58+
}]
59+
```
60+
861
## License
962

1063
[MIT](LICENSE)

0 commit comments

Comments
 (0)