|
|
|
@ -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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|