lesser evil

pull/8577/head
gtmnayan 3 years ago
parent 86a8a13cfc
commit 9b1c6e522b

@ -102,7 +102,7 @@ function cleanChildren(node) {
});
// recurse
[...node.childNodes].forEach((child) => {
for (let child of node.childNodes) {
if (child.nodeType === 3) {
// text
if (
@ -130,7 +130,7 @@ function cleanChildren(node) {
}
previous = child;
});
}
// collapse whitespace
if (node.firstChild && node.firstChild.nodeType === 3) {

@ -43,8 +43,23 @@ function normalizeHtml(window, html) {
.replace(/<!--.*?-->/g, '')
.replace(/>[\s\r\n]+</g, '><')
.trim();
cleanStyle(node);
return node.innerHTML.replace(/<\/?noscript\/?>/g, '');
} catch (err) {
throw new Error(`Failed to normalize HTML:\n${html}`);
}
}
function cleanStyle(node) {
if (node.nodeType === 1) {
if (node.hasAttribute('style')) {
node.style = node.style.cssText;
}
for (const child of node.childNodes) {
cleanStyle(child);
}
}
}

Loading…
Cancel
Save