* 把一个链接目标解析为应当存在的本地文件;返回 null 表示无需校验 * (外部链接、页内锚点、空目标)。
(file, rawTarget)
| 51 | * (外部链接、页内锚点、空目标)。 |
| 52 | */ |
| 53 | function resolveTarget(file, rawTarget) { |
| 54 | let t = rawTarget.trim(); |
| 55 | if (!t) return null; |
| 56 | // 去掉 Markdown 链接里的可选 title: [x](path "title") |
| 57 | t = t.replace(/\s+["'].*$/, "").trim(); |
| 58 | if (!t || isExternal(t)) return null; |
| 59 | if (t.startsWith("#/")) return routeToFile(t.slice(1)); |
| 60 | if (t.startsWith("#")) return null; // 页内锚点,不校验 |
| 61 | const pathPart = t.split("#")[0].split("?")[0]; |
| 62 | if (!pathPart) return null; |
| 63 | try { |
| 64 | return resolve(dirname(file), decodeURIComponent(pathPart)); |
| 65 | } catch { |
| 66 | return resolve(dirname(file), pathPart); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | const MD_LINK_RE = /!?\[[^\]]*\]\(([^)]+)\)/g; // [text](t) 与  |
| 71 | const HREF_RE = /href\s*=\s*["']([^"']+)["']/gi; // <a href="..."> |
no test coverage detected