Parcourir la source

better fix for urls resolving issues

Gildas il y a 7 ans
Parent
commit
1c64e7854b
1 fichiers modifiés avec 16 ajouts et 8 suppressions
  1. 16 8
      lib/single-file/single-file-core.js

+ 16 - 8
lib/single-file/single-file-core.js

@@ -517,7 +517,13 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 				if (!initialization) {
 					this.stats.add("processed", "styleSheets", 1);
 				}
-				const stylesheetContent = initialization ? await DomProcessorHelper.resolveImportURLs(styleElement.textContent, this.baseURI, { maxResourceSize: this.options.maxResourceSize, maxResourceSizeEnabled: this.options.maxResourceSizeEnabled }) : await DomProcessorHelper.processStylesheet(styleElement.textContent, this.baseURI);
+				let stylesheetContent = styleElement.textContent;
+				if (initialization) {
+					stylesheetContent = DomProcessorHelper.resolveStylesheetURLs(stylesheetContent, this.baseURI);
+					stylesheetContent = await DomProcessorHelper.resolveImportURLs(styleElement.textContent, this.baseURI, { maxResourceSize: this.options.maxResourceSize, maxResourceSizeEnabled: this.options.maxResourceSizeEnabled });
+				} else {
+					stylesheetContent = await DomProcessorHelper.processStylesheet(styleElement.textContent, this.baseURI);
+				}
 				styleElement.textContent = stylesheetContent;
 			}));
 		}
@@ -616,7 +622,12 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 
 		async attributeStyles(initialization) {
 			await Promise.all(Array.from(this.doc.querySelectorAll("[style]")).map(async element => {
-				const stylesheetContent = initialization ? await DomProcessorHelper.resolveImportURLs(element.getAttribute("style"), this.baseURI, { maxResourceSize: this.options.maxResourceSize, maxResourceSizeEnabled: this.options.maxResourceSizeEnabled }) : await DomProcessorHelper.processStylesheet(element.getAttribute("style"), this.baseURI);
+				let stylesheetContent = element.getAttribute("style");
+				if (initialization) {
+					stylesheetContent = DomProcessorHelper.resolveStylesheetURLs(stylesheetContent, this.baseURI);
+				} else {
+					stylesheetContent = await DomProcessorHelper.processStylesheet(element.getAttribute("style"), this.baseURI);
+				}
 				element.setAttribute("style", stylesheetContent);
 			}));
 		}
@@ -691,17 +702,13 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 						importedStylesheetContent = DomUtil.wrapMediaQuery(importedStylesheetContent, match.media);
 						if (stylesheetContent.indexOf(cssImport) != -1) {
 							importedStylesheetContent = DomProcessorHelper.resolveStylesheetURLs(importedStylesheetContent, styleSheetUrl);
+							DomProcessorHelper.resolveImportURLs(importedStylesheetContent, styleSheetUrl, options);
 							stylesheetContent = stylesheetContent.replace(cssImport, importedStylesheetContent);
 						}
 					}
 				}
 			}));
-			stylesheetContent = DomProcessorHelper.resolveStylesheetURLs(stylesheetContent, baseURI);
-			if (imports.length) {
-				return await DomProcessorHelper.resolveImportURLs(stylesheetContent, baseURI, options);
-			} else {
-				return stylesheetContent;
-			}
+			return stylesheetContent;
 		}
 
 		static resolveStylesheetURLs(stylesheetContent, baseURI) {
@@ -720,6 +727,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 			resourceURL = DomUtil.normalizeURL(resourceURL);
 			if (resourceURL && resourceURL != baseURI && resourceURL != ABOUT_BLANK_URI) {
 				let stylesheetContent = await Download.getContent(resourceURL, { asDataURI: false, maxResourceSize: options.maxResourceSize, maxResourceSizeEnabled: options.maxResourceSizeEnabled });
+				stylesheetContent = DomProcessorHelper.resolveStylesheetURLs(stylesheetContent, resourceURL);
 				stylesheetContent = await DomProcessorHelper.resolveImportURLs(stylesheetContent, resourceURL, options);
 				stylesheetContent = DomUtil.wrapMediaQuery(stylesheetContent, media);
 				return stylesheetContent;