Sfoglia il codice sorgente

remove invalid elements in foreignObject tags

Former-commit-id: 81806edc33101bac95d3a96a281d45d87c81c39a
Gildas 6 anni fa
parent
commit
239a08f48d
1 ha cambiato i file con 7 aggiunte e 0 eliminazioni
  1. 7 0
      lib/single-file/single-file-helper.js

+ 7 - 0
lib/single-file/single-file-helper.js

@@ -100,6 +100,13 @@ this.singlefile.lib.helper = this.singlefile.lib.helper || (() => {
 		if (doc.head) {
 			doc.head.querySelectorAll("*:not(base):not(link):not(meta):not(noscript):not(script):not(style):not(template):not(title)").forEach(element => element.hidden = true);
 		}
+		doc.querySelectorAll("svg foreignObject").forEach(element => {
+			const flowElements = element.querySelectorAll("html > head > *:not(base):not(link):not(meta):not(noscript):not(script):not(style):not(template):not(title), html > body > *:not(base):not(link):not(meta):not(noscript):not(script):not(style):not(template):not(title)");
+			if (flowElements.length) {
+				Array.from(element.childNodes).forEach(node => node.remove());
+				flowElements.forEach(flowElement => element.appendChild(flowElement));
+			}
+		});
 		let elementsInfo;
 		if (win && doc.documentElement) {
 			elementsInfo = getElementsInfo(win, doc, doc.documentElement, options);