Skip to content

Commit a27b735

Browse files
committed
【修复】优化链接处理逻辑
- 更新 markdown-html 版本至 1.18.9 - 扩展链接处理范围,支持所有非空 href 属性的 a 标签 - 对于 .md 文件使用内部路由,其他文件使用原始路径
1 parent e21b1c8 commit a27b735

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

index.html

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<html>
44
<markdown-html
5-
version="1.18.8"
5+
version="1.18.9"
66
author="PJ568"
77
repo="https://github.com/PJ-568/markdown.html"
88
license="CC BY-SA 4.0 International"
@@ -611,8 +611,8 @@
611611
"text/html"
612612
);
613613

614-
//// 处理所有以 .md 结尾的链接
615-
const mdLinks = linkDoc.querySelectorAll('a[href$=".md"]');
614+
//// 处理所有 a 链接
615+
const mdLinks = linkDoc.querySelectorAll('a[href]:not([href=""])');
616616
mdLinks.forEach((link) => {
617617
const href = link.getAttribute("href");
618618
if (!isExternalLink(href) && isRelativePath(href)) {
@@ -621,7 +621,11 @@
621621
: getPath() + href;
622622
absolutePath = new URL(absolutePath, "http://example.com")
623623
.pathname;
624-
link.setAttribute("href", `?p=${absolutePath}`);
624+
if (absolutePath.endsWith(".md")) {
625+
link.setAttribute("href", `?p=${absolutePath}`);
626+
} else {
627+
link.setAttribute("href", absolutePath);
628+
}
625629
}
626630
});
627631

0 commit comments

Comments
 (0)