File tree 1 file changed +56
-3
lines changed
1 file changed +56
-3
lines changed Original file line number Diff line number Diff line change
1
+ # html-parse-string
1
2
HTML parse and stringify utils
2
3
3
- Installation
4
- ============
4
+ ## Installation
5
5
6
- npm install html-parse-string
6
+ ```
7
+ npm install html-parse-string
8
+ ```
9
+
10
+ ## IDom
11
+ basic data structure
12
+ ```
13
+ export interface IDom {
14
+ type: string;
15
+ content ? : string;
16
+ voidElement: boolean;
17
+ name: string;
18
+ attrs: { [key: string]: any };
19
+ children: IDom[];
20
+ }
21
+
22
+ ```
23
+
24
+ ## parse
25
+ parse html to idom array
26
+ ```
27
+ const { parse, stringify } = require('html-parse-string');
28
+ const t = `<div>this is div</div>`;
29
+ console.log(parse(t));
30
+ ```
31
+ get idom array
32
+ ```
33
+ [
34
+ {
35
+ type: "tag",
36
+ name: "div",
37
+ voidElement: false,
38
+ attrs: {},
39
+ children: [
40
+ {
41
+ type: "text",
42
+ content: "this is div",
43
+ },
44
+ ],
45
+ },
46
+ ];
47
+ ```
48
+ ## stringify
49
+ stringify idom array to html
50
+ ```
51
+ const { parse, stringify } = require('html-parse-string');
52
+ const t = `<div>this is div</div>`;
53
+ const ast = parse(t);
54
+ console.log(stringify(ast));
55
+ ```
56
+ get html string
57
+ ```
58
+ <div>this is div</div>
59
+ ```
You can’t perform that action at this time.
0 commit comments