Skip to content

Commit f096f08

Browse files
committed
【修复】更新版本号并优化链接协议判断逻辑
改进链接协议判断功能: - 重命名 isExternalLink 函数中的内部逻辑为 isProtocol - 添加对 ftp 和 about 协议的支持 - 重构外链判断逻辑,增加相对路径验证 - 修复链接处理中的协议判断条件
1 parent 568b28e commit f096f08

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

index.html

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

33
<html>
44
<markdown-html
5-
version="1.20.10"
5+
version="1.20.11"
66
author="PJ568"
77
repo="https://github.com/PJ-568/markdown.html"
88
license="CC BY-SA 4.0 International"
@@ -313,20 +313,31 @@
313313
return mdPath;
314314
}
315315

316-
// 判断链接是否为外链
317-
function isExternalLink(url) {
318-
if (!url || typeof url !== "string") return false;
319-
316+
// 判断是否为其它协议(是 HTTP(S) 协议)
317+
function isProtocol(url) {
320318
//// 排除特殊协议
321319
const excludedProtocols = [
322320
"#",
323321
"javascript:",
324322
"mailto:",
325323
"tel:",
326324
"data:",
325+
"ftp:",
326+
"about:",
327327
];
328328
if (excludedProtocols.some((proto) => url.startsWith(proto))) {
329329
return false;
330+
} else {
331+
return true;
332+
}
333+
}
334+
335+
// 判断链接是否为外链
336+
function isExternalLink(url) {
337+
if (!url || typeof url !== "string") return false;
338+
339+
if (!isProtocol(url)) {
340+
return false;
330341
}
331342

332343
try {
@@ -615,7 +626,8 @@
615626
const mdLinks = linkDoc.querySelectorAll('a[href]:not([href=""])');
616627
mdLinks.forEach((link) => {
617628
const href = link.getAttribute("href");
618-
if (!isExternalLink(href) && isRelativePath(href)) {
629+
//// 是相对路径
630+
if (!isExternalLink(href) && isRelativePath(href) && isProtocol(href)) {
619631
var absolutePath = pValue
620632
? getDirectory(mdPath) + href
621633
: getPath() + href;

0 commit comments

Comments
 (0)