瀏覽代碼

don't insert empty stylesheet

Gildas 7 年之前
父節點
當前提交
408d3b795a
共有 1 個文件被更改,包括 9 次插入7 次删除
  1. 9 7
      lib/single-file/single-file-core.js

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

@@ -632,13 +632,15 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 						stylesheetContent += stylesContent + "}";
 					}
 				});
-				const styleElement = this.doc.createElement("style");
-				styleElement.textContent = stylesheetContent;
-				const existingStyleElement = this.doc.querySelector("style");
-				if (existingStyleElement) {
-					existingStyleElement.parentElement.insertBefore(styleElement, existingStyleElement);
-				} else {
-					this.doc.head.insertBefore(styleElement, this.doc.head.firstChild);
+				if (stylesheetContent) {
+					const styleElement = this.doc.createElement("style");
+					styleElement.textContent = stylesheetContent;
+					const existingStyleElement = this.doc.querySelector("style");
+					if (existingStyleElement) {
+						existingStyleElement.parentElement.insertBefore(styleElement, existingStyleElement);
+					} else {
+						this.doc.head.insertBefore(styleElement, this.doc.head.firstChild);
+					}
 				}
 			}
 		}