File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55
66Parse 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 )
You can’t perform that action at this time.
0 commit comments