Explorar el Código

remove empty script and empty style tags

Gildas hace 7 años
padre
commit
e59b30eb76
Se han modificado 1 ficheros con 9 adiciones y 0 borrados
  1. 9 0
      lib/single-file/single-file-core.js

+ 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());
 		}