UNPKG

@trap_stevo/legendarybuilderproreact-ui

Version:

The legendary UI & utility API that makes your application a legendary application. ~ Created by Steven Compton

48 lines 1.61 kB
import DOMPurify from "dompurify"; export var containsHTML = function containsHTML(input) { return /<\/?[a-z][\s\S]*>/i.test(input); }; export var sanitizeHTML = function sanitizeHTML(html) { return DOMPurify.sanitize(html, { ADD_TAGS: ["iframe", "button"], ADD_ATTR: ["src", "width", "height", "frameborder", "allow", "allowfullscreen", "scrolling", "style", "type", "onclick"], FORBID_TAGS: ["style"], WHOLE_DOCUMENT: false, SANITIZE_DOM: true, ALLOW_ARIA_ATTR: true, KEEP_CONTENT: true, ADD_POLICY_FACTORY: function ADD_POLICY_FACTORY() { return { transform: { element: function element(nodeName, node) { if (nodeName === "body" || nodeName === "html") { return null; } return { nodeName: nodeName, node: node }; }, attribute: function attribute(attrName, attrValue) { if (attrName === "style") { var forbiddenStyles = ["position: fixed", "position: absolute", "position: sticky"]; var styleRules = attrValue.split(";").filter(function (rule) { return !forbiddenStyles.some(function (forbiddenStyle) { return rule.includes(forbiddenStyle); }); }); return { attrName: attrName, attrValue: styleRules.join(";") }; } return { attrName: attrName, attrValue: attrValue }; } } }; } }); };