Skip to content

Commit dcfdc96

Browse files
authored
Merge pull request #6 from this-spring/master
feat: add md
2 parents e717da6 + 02484bf commit dcfdc96

File tree

1 file changed

+56
-3
lines changed

1 file changed

+56
-3
lines changed

README.md

+56-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,59 @@
1+
# html-parse-string
12
HTML parse and stringify utils
23

3-
Installation
4-
============
4+
## Installation
55

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+
```

0 commit comments

Comments
 (0)