# afu-xhtml

> A library for filtering HTML tags and attributes written in JavaScript

Latest version **2.0.5** (published 2018-07-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install afu-xhtml
pnpm add afu-xhtml
yarn add afu-xhtml
bun add afu-xhtml
```

## 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 | 2.0.5 |
| Published | 2018-07-17 |
| First published | 2018-07-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 3.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | afu |
| Maintainers | solipu |
| Keywords | filter, html, attributes, tags |

## Links

- npm: https://www.npmjs.com/package/afu-xhtml
- Repository: https://github.com/yulipu/html-filter
- Homepage: https://github.com/yulipu/html-filter#readme
- Issues: https://github.com/yulipu/html-filter
- npm.io page: https://npm.io/package/afu-xhtml

## Dependencies (1)

- [html-filter](https://npm.io/package/html-filter.md) ^1.0.2

## Alternatives

- [@tsparticles/shape-image](https://npm.io/package/@tsparticles/shape-image.md) — 303.7K weekly downloads
- [@tsparticles/shape-line](https://npm.io/package/@tsparticles/shape-line.md) — 233.7K weekly downloads
- [stringify-attributes](https://npm.io/package/stringify-attributes.md) — 58.6K weekly downloads
- [mobile-drag-drop](https://npm.io/package/mobile-drag-drop.md) — 46.3K weekly downloads
- [@comunica/actor-rdf-parse-html](https://npm.io/package/@comunica/actor-rdf-parse-html.md) — 29.2K weekly downloads

## Recent versions

- 2.0.5 (latest) — 2018-07-17
- 2.0.4 — 2018-07-16
- 2.0.3 — 2018-07-16
- 2.0.2 — 2018-07-16
- 2.0.1 — 2018-07-16
- 2.0.0 — 2018-07-16
- 1.0.3 — 2018-07-16
- 1.0.2 — 2018-07-16
- 1.0.1 — 2018-07-14
- 1.0.0 — 2018-07-14

## README

# npm 包已经更名为 html-filter 请安装 html-filter

## html 过滤库 A library for filtering HTML tags and attributes written in JavaScript

### change log

+ npm 2.0.1 change attributes config
+ npm 包更名为 html-filter 请安装 html-filter

### 过滤标签和属性 - filter tags and attributes

```
var html =
`
<h1><br /><h1>user info</h1></h1>
<div id="myid" style="border: 1px solid red">
    <div style="font-weight: bold">Hello</div>
    <br />
    <div id="user" onclick="alert(1)">
        <p>zhangsan</p>
        <p>male</p>
        <p>20</p>
    </div>
</div>
`;

var obj = new XHtml();
obj.allowedTags = {
    p: null,  // not support attr
    div: {id: 1, style: 1},  // support id and style attr
    br: null
};
obj.parse(html);

console.log(obj.getHtml())

// the console result:
<div id="myid" style="border: 1px solid red">
    <div style="font-weight: bold">Hello</div>
    <br />
    <div id="user">
        <p>zhangsan</p>
        <p>male</p>
        <p>20</p>
    </div>
</div>
```

### html 转 DOM - translate html string to DOM Element

```
var html =
`
<h1><br /><h1>user info</h1></h1>
<div id="myid" style="border: 1px solid red">
    <div style="font-weight: bold">Hello</div>
    <br />
    <div id="user" onclick="alert(1)">
        <p>zhangsan</p>
        <p>male</p>
        <p>20</p>
    </div>
</div>
`;

var obj = new XHtml.XDom();
obj.allowedTags = {
    p: null,  // not support attr
    div: {id: 1, style: 1},  // support id and style attr
    br: null
};
obj.parse(html);

console.log(obj.getDom());
```

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