single-file-core 1.5.20 → 1.5.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/core/index.js +27 -9
  2. package/package.json +1 -1
package/core/index.js CHANGED
@@ -1085,12 +1085,34 @@ class Processor {
1085
1085
  }
1086
1086
 
1087
1087
  resolveHrefs() {
1088
- this.doc.querySelectorAll("a[href], area[href], link[href]").forEach(element => {
1089
- const href = element.getAttribute("href").trim();
1090
- if (element.tagName.toUpperCase() == "LINK" && element.rel.includes("stylesheet")) {
1091
- if (this.options.saveOriginalURLs && !isDataURL(href)) {
1092
- element.setAttribute("data-sf-original-href", href);
1088
+ if (this.options.resolveLinks === undefined || this.options.resolveLinks) {
1089
+ this.doc.querySelectorAll("a[href], area[href]").forEach(element => {
1090
+ const href = element.getAttribute("href").trim();
1091
+ if (!testIgnoredPath(href)) {
1092
+ let resolvedURL;
1093
+ try {
1094
+ resolvedURL = util.resolveURL(href, this.options.baseURI || this.options.url);
1095
+ } catch (error) {
1096
+ // ignored
1097
+ }
1098
+ if (resolvedURL) {
1099
+ const url = normalizeURL(this.options.url);
1100
+ if (resolvedURL.startsWith(url + "#") && !resolvedURL.startsWith(url + "#!") && !this.options.resolveFragmentIdentifierURLs) {
1101
+ resolvedURL = resolvedURL.substring(url.length);
1102
+ }
1103
+ try {
1104
+ element.setAttribute("href", resolvedURL);
1105
+ } catch (error) {
1106
+ // ignored
1107
+ }
1108
+ }
1093
1109
  }
1110
+ });
1111
+ }
1112
+ this.doc.querySelectorAll("link[href]").forEach(element => {
1113
+ const href = element.getAttribute("href").trim();
1114
+ if (element.rel.includes("stylesheet") && this.options.saveOriginalURLs && !isDataURL(href)) {
1115
+ element.setAttribute("data-sf-original-href", href);
1094
1116
  }
1095
1117
  if (!testIgnoredPath(href)) {
1096
1118
  let resolvedURL;
@@ -1100,10 +1122,6 @@ class Processor {
1100
1122
  // ignored
1101
1123
  }
1102
1124
  if (resolvedURL) {
1103
- const url = normalizeURL(this.options.url);
1104
- if (resolvedURL.startsWith(url + "#") && !resolvedURL.startsWith(url + "#!") && !this.options.resolveFragmentIdentifierURLs) {
1105
- resolvedURL = resolvedURL.substring(url.length);
1106
- }
1107
1125
  try {
1108
1126
  element.setAttribute("href", resolvedURL);
1109
1127
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "single-file-core",
3
- "version": "1.5.20",
3
+ "version": "1.5.22",
4
4
  "description": "SingleFile Core",
5
5
  "author": "Gildas Lormeau",
6
6
  "license": "AGPL-3.0-or-later",