Просмотр исходного кода

remove meta[charset] from the head when body is empty

Gildas 7 лет назад
Родитель
Сommit
6fc2b2eac0
1 измененных файлов с 5 добавлено и 2 удалено
  1. 5 2
      lib/single-file/single-file-core.js

+ 5 - 2
lib/single-file/single-file-core.js

@@ -187,7 +187,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 			if (this.options.insertSingleFileComment) {
 				this.processor.insertSingleFileCommentNode();
 			}
-			this.processor.removeBase();
+			this.processor.removeDefaultHeadTags();
 		}
 
 		getPageData() {
@@ -466,8 +466,11 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 			}
 		}
 
-		removeBase() {
+		removeDefaultHeadTags() {
 			this.doc.querySelectorAll("base").forEach(element => element.remove());
+			if (this.doc.head.querySelectorAll("*").length == 1 && this.doc.head.querySelector("meta[charset]") && this.doc.body.childNodes.length == 0) {
+				this.doc.head.querySelector("meta[charset]").remove();
+			}
 		}
 
 		removeInfoToolbar() {