Parcourir la source

added cleanupPage task

Former-commit-id: 331f2fd004b8b9a8d8e4a2dec23a490960da1bec
Gildas il y a 6 ans
Parent
commit
6aa352526c
1 fichiers modifiés avec 15 ajouts et 11 suppressions
  1. 15 11
      lib/single-file/single-file-core.js

+ 15 - 11
lib/single-file/single-file-core.js

@@ -134,7 +134,8 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
 			{ action: "replaceStylesheets" },
 			{ action: "replaceStyleAttributes" },
 			{ action: "insertVariables" },
-			{ option: "compressHTML", action: "compressHTML" }
+			{ option: "compressHTML", action: "compressHTML" },
+			{ action: "cleanupPage" }
 		],
 		parallel: [
 			{ option: "enableMaff", action: "insertMAFFMetaData" },
@@ -198,7 +199,7 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
 			await this.pendingPromises;
 			await this.executeStage(REPLACE_DOCS_STAGE);
 			await this.executeStage(POST_PROCESS_STAGE);
-			await this.processor.finalize();
+			this.processor.finalize();
 		}
 
 		getDocument() {
@@ -401,18 +402,10 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
 			this.onEventAttributeNames = Util.getOnEventAttributeNames(this.doc);
 		}
 
-		async finalize() {
+		finalize() {
 			if (this.workStyleElement.parentNode) {
 				this.workStyleElement.remove();
 			}
-			this.doc.querySelectorAll("base").forEach(element => element.remove());
-			const metaCharset = this.doc.head.querySelector("meta[charset]");
-			if (metaCharset) {
-				this.doc.head.insertBefore(metaCharset, this.doc.head.firstChild);
-				if (this.doc.head.querySelectorAll("*").length == 1 && this.doc.body.childNodes.length == 0) {
-					this.doc.head.querySelector("meta[charset]").remove();
-				}
-			}
 		}
 
 		async getPageData() {
@@ -1216,6 +1209,17 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
 			}
 		}
 
+		cleanupPage() {
+			this.doc.querySelectorAll("base").forEach(element => element.remove());
+			const metaCharset = this.doc.head.querySelector("meta[charset]");
+			if (metaCharset) {
+				this.doc.head.insertBefore(metaCharset, this.doc.head.firstChild);
+				if (this.doc.head.querySelectorAll("*").length == 1 && this.doc.body.childNodes.length == 0) {
+					this.doc.head.querySelector("meta[charset]").remove();
+				}
+			}
+		}
+
 		async insertMAFFMetaData() {
 			const maffMetaData = await this.maffMetaDataPromise;
 			if (maffMetaData && maffMetaData.content) {