# html-ast-parse-stringify

> 将html解析为ast

Latest version **1.0.1** (published 2020-04-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install html-ast-parse-stringify
pnpm add html-ast-parse-stringify
yarn add html-ast-parse-stringify
bun add html-ast-parse-stringify
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2020-04-21 |
| First published | 2020-04-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 13.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | https://github.com/zzh-15 |
| Maintainers | hikigaya |
| Keywords | html, parse, stringify, ast |

## Links

- npm: https://www.npmjs.com/package/html-ast-parse-stringify
- npm.io page: https://npm.io/package/html-ast-parse-stringify

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2020-04-21
- 1.0.0 — 2020-04-21

## README

# html-ast-parse-stringify
将html解析并转化为ast

## 安装
---
```
npm install html-ast-parse-stringify --save
```

## 使用
---
```javascript
const { parse, stringify } = require('html-ast-parse-stringify')

let html = '<div class="red"><p>Hello, World</p></div>'

let ast = parse(html)

console.log(ast)

/*
{
	"type": "root",
	"childrens": [{
		"type": "tag",
		"name": "div",
		"attrs": [{
			"name": "class",
			"value": "red"
		}],
		"childrens": [{
			"type": "tag",
			"name": "p",
			"attrs": [],
			"childrens": [{
				"type": "text",
				"value": "Hello, World"
			}]
		}]
	}]
}
*/

console.log(stringify(ast))
// <div class="red"><p>Hello, World</p></div>
```
## AST节点类型
---

### 标签
* `type`: 节点类型(tag)
* `name`: 标签名
* `attrs`: 属性数组
* `childrens`: 子节点数组

### 文本
* `type`: 节点类型(text)
* `value`: 文本值

### DOCTYPE

* `type`: 节点类型(doctype)
* `value`: 类型声明内容

## 注意事项
1. 除 `<br>`、`<hr>`、`<img>`、`<link>`、`<base>`、`<area>`、`<input>`、`<source>`等标签外，所有的标签必须严格闭合。
2. 无法解析`<script>`

## license
MIT

---
_Source: https://npm.io/package/html-ast-parse-stringify · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
