فهرست منبع

【修复】优化链接处理逻辑

- 更新 markdown-html 版本至 1.18.9
- 扩展链接处理范围,支持所有非空 href 属性的 a 标签
- 对于 .md 文件使用内部路由,其他文件使用原始路径
PJ568 1 سال پیش
والد
کامیت
a27b735db2
1فایلهای تغییر یافته به همراه8 افزوده شده و 4 حذف شده
  1. 8 4
      index.html

+ 8 - 4
index.html

@@ -2,7 +2,7 @@
 
 <html>
   <markdown-html
-    version="1.18.8"
+    version="1.18.9"
     author="PJ568"
     repo="https://github.com/PJ-568/markdown.html"
     license="CC BY-SA 4.0 International"
@@ -611,8 +611,8 @@
             "text/html"
           );
 
-          //// 处理所有以 .md 结尾的链接
-          const mdLinks = linkDoc.querySelectorAll('a[href$=".md"]');
+          //// 处理所有 a 链接
+          const mdLinks = linkDoc.querySelectorAll('a[href]:not([href=""])');
           mdLinks.forEach((link) => {
             const href = link.getAttribute("href");
             if (!isExternalLink(href) && isRelativePath(href)) {
@@ -621,7 +621,11 @@
                 : getPath() + href;
               absolutePath = new URL(absolutePath, "http://example.com")
                 .pathname;
-              link.setAttribute("href", `?p=${absolutePath}`);
+              if (absolutePath.endsWith(".md")) {
+                link.setAttribute("href", `?p=${absolutePath}`);
+              } else {
+                link.setAttribute("href", absolutePath);
+              }
             }
           });