Przeglądaj źródła

move meta[charset] to the top of the head tags

Gildas 7 lat temu
rodzic
commit
b9397f93a9
1 zmienionych plików z 5 dodań i 1 usunięć
  1. 5 1
      lib/single-file/single-file-core.js

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

@@ -416,9 +416,13 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 		}
 
 		cleanup() {
+			const metaCharset = this.doc.head.querySelector("meta[charset]");
+			if (metaCharset) {
+				this.doc.head.insertBefore(metaCharset, this.doc.head.firstChild);
+			}
 			this.doc.querySelectorAll("style[data-single-file-sheet]").forEach(element => element.removeAttribute("data-single-file-sheet"));
 			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) {
+			if (this.doc.head.querySelectorAll("*").length == 1 && metaCharset && this.doc.body.childNodes.length == 0) {
 				this.doc.head.querySelector("meta[charset]").remove();
 			}
 		}