@sika7/sanitize-html
TypeScript icon, indicating that this package has built-in type declarations

0.0.0 • Public • Published

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
  },
};
setting description example
tag allow tag name. div
allowAttrs allow attributes. ['class','style']
allowStyle allow styles. require style in allowAttrs. ['color','text-align']

Package Sidebar

Install

npm i @sika7/sanitize-html

Weekly Downloads

0

Version

0.0.0

License

MIT

Unpacked Size

6.85 kB

Total Files

7

Last publish

Collaborators

  • sika7