@sika7/sanitize-html
v0.0.0
Published
this package is html sanitize Provide.
Downloads
8
Maintainers
Readme
@sika7/sanitize-html
this package is html sanitize. You can allow the attributes of each tag.
Usage
Step 1: Install plugin:
npm install --save @sika7/sanitize-html
Step 2: add a functions or plugin.
import { sanitizeHtml } from "@sika7/sanitize-html";
const result = sanitizeHtml("<div><p>test</p><div>test</div></div>", [
{
tag: "div",
allowAttrs: ["class", "style"],
allowStyle: ["color"],
},
]);
console.log(result);
// # <div><div>test</div></div>
config
import { allowTag } from "@sika7/sanitize-html";
const allowTags: allowTag[] = {
{
tag: "div", // require
allowAttrs: ["class", "style"], // options
allowStyle: ["color"], // options
},
};
| setting | description | example | | ---------- | ------------------------------------------ | ---------------------- | | tag | allow tag name. | div | | allowAttrs | allow attributes. | ['class','style'] | | allowStyle | allow styles. require style in allowAttrs. | ['color','text-align'] |