فهرست منبع

better handling of links pointing to anchors in the saved page

Gildas 6 سال پیش
والد
کامیت
0d8f70d4ad
1فایلهای تغییر یافته به همراه13 افزوده شده و 2 حذف شده
  1. 13 2
      lib/single-file/single-file-core.js

+ 13 - 2
lib/single-file/single-file-core.js

@@ -765,12 +765,23 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 		resolveHrefs() {
 			this.doc.querySelectorAll("a[href], area[href], link[href]").forEach(element => {
 				const href = element.getAttribute("href").trim();
-				if (!Util.testIgnoredPath(href) && !href.startsWith("#")) {
+				if (!Util.testIgnoredPath(href)) {
+					let resolvedURL;
 					try {
-						element.setAttribute("href", docUtil.resolveURL(href, this.options.baseURI || this.options.url));
+						resolvedURL = docUtil.resolveURL(href, this.options.baseURI || this.options.url);
 					} catch (error) {
 						// ignored
 					}
+					if (resolvedURL) {
+						if (resolvedURL.startsWith(this.options.url + "#")) {
+							resolvedURL = resolvedURL.substring(this.options.url.length);
+						}
+						try {
+							element.setAttribute("href", resolvedURL);
+						} catch (error) {
+							// ignored
+						}
+					}
 				}
 			});
 		}