فهرست منبع

don't insert empty stylesheets

Gildas 7 سال پیش
والد
کامیت
db459b3794
1فایلهای تغییر یافته به همراه9 افزوده شده و 5 حذف شده
  1. 9 5
      lib/single-file/single-file-core.js

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

@@ -830,12 +830,16 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 			await Promise.all(Array.from(this.doc.querySelectorAll("link[rel*=stylesheet]")).map(async linkElement => {
 				const options = { maxResourceSize: this.options.maxResourceSize, maxResourceSizeEnabled: this.options.maxResourceSizeEnabled, charSet: this.charSet };
 				const stylesheetContent = await DomProcessorHelper.resolveLinkStylesheetURLs(linkElement.href, this.baseURI, options);
-				const styleElement = this.doc.createElement("style");
-				if (linkElement.media) {
-					styleElement.media = linkElement.media;
+				if (stylesheetContent) {
+					const styleElement = this.doc.createElement("style");
+					if (linkElement.media) {
+						styleElement.media = linkElement.media;
+					}
+					styleElement.textContent = stylesheetContent;
+					linkElement.parentElement.replaceChild(styleElement, linkElement);
+				} else {
+					linkElement.remove();
 				}
-				styleElement.textContent = stylesheetContent;
-				linkElement.parentElement.replaceChild(styleElement, linkElement);
 			}));
 		}
 	}