Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@sika7/sanitize-html

sika712MIT0.0.0TypeScript support: included

this package is html sanitize Provide.

html-sanitize, sanitize, html, whitelist, allow for each tag

readme

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']