1
0
Эх сурвалжийг харах

remove empty script and empty style tags

Gildas 7 жил өмнө
parent
commit
e59b30eb76

+ 9 - 0
lib/single-file/single-file-core.js

@@ -148,6 +148,7 @@ this.SingleFileCore = (() => {
 			if (!this.options.removeImports) {
 				await this.processor.htmlImports();
 			}
+			this.processor.removeEmptyInlineElements();
 		}
 
 		getPageData() {
@@ -304,6 +305,14 @@ this.SingleFileCore = (() => {
 			this.doc.querySelectorAll("audio[src], audio > source[src], video[src], video > source[src]").forEach(element => element.removeAttribute("src"));
 		}
 
+		removeEmptyInlineElements() {
+			this.doc.querySelectorAll("style, script").forEach(element => {
+				if (element.textContent.trim() == "") {
+					element.remove();
+				}
+			});
+		}
+
 		removeScripts() {
 			this.doc.querySelectorAll("script:not([type=\"application/ld+json\"])").forEach(element => element.remove());
 		}