0.0.0 • Published 2 years ago

@sika7/sanitize-html v0.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

License: MIT

@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
  },
};
settingdescriptionexample
tagallow tag name.div
allowAttrsallow attributes.'class','style'
allowStyleallow styles. require style in allowAttrs.'color','text-align'