This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function cleanHtml(html) { | |
const parser = new DOMParser() | |
const doc = parser.parseFromString(html || document.querySelector('html').innerHTML, 'text/html') | |
const allowedAttrs = ['href', 'src', 'alt', 'title', 'aria-*'] | |
const allowedTags = ['div', 'span', 'p', 'a', 'img', 'ul', 'ol', 'li', 'strong', 'em', 'u', 'b', 'i'] | |
const disallowedTags = ['script', 'style', 'meta', 'link', 'iframe', 'svg', 'noscript'] | |
doc.querySelectorAll('*').forEach((elm) => { | |
const tagName = elm.tagName.toLowerCase() |