File tree 1 file changed +53
-0
lines changed
1 file changed +53
-0
lines changed Original file line number Diff line number Diff line change 5
5
6
6
Parse HTML/XML to [ PostHTMLTree] ( https://github.com/posthtml/posthtml#posthtml-json-tree-example )
7
7
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
+
8
61
## License
9
62
10
63
[ MIT] ( LICENSE )
You can’t perform that action at this time.
0 commit comments