lesser evil

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

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

@ -43,8 +43,23 @@ function normalizeHtml(window, html) {
.replace(/<!--.*?-->/g, '') .replace(/<!--.*?-->/g, '')
.replace(/>[\s\r\n]+</g, '><') .replace(/>[\s\r\n]+</g, '><')
.trim(); .trim();
cleanStyle(node);
return node.innerHTML.replace(/<\/?noscript\/?>/g, ''); return node.innerHTML.replace(/<\/?noscript\/?>/g, '');
} catch (err) { } catch (err) {
throw new Error(`Failed to normalize HTML:\n${html}`); 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