(content: string)
| 182 | } |
| 183 | |
| 184 | export function parseWikilinks(content: string): WikiLink[] { |
| 185 | // 用 matchAll 而非 exec 循环: |
| 186 | // - matchAll 内部独立维护 iterator state,**不依赖共享 regex 的 lastIndex** |
| 187 | // - 高并发场景下两个请求同时进入此函数也不会互相覆盖匹配位置 |
| 188 | const out: WikiLink[] = []; |
| 189 | for (const m of content.matchAll(WIKILINK_RE)) { |
| 190 | if (m.index === undefined) continue; |
| 191 | const { alias, relation } = splitAliasOrRelation(m[3]); |
| 192 | out.push({ |
| 193 | target: m[1], |
| 194 | anchor: m[2] || null, |
| 195 | alias, |
| 196 | relation, |
| 197 | raw: m[0], |
| 198 | start: m.index, |
| 199 | end: m.index + m[0].length, |
| 200 | }); |
| 201 | } |
| 202 | return out; |
| 203 | } |
| 204 | |
| 205 | /** 标准化链接目标:补 .md 后缀 */ |
| 206 | export function normalizeLinkTarget(target: string): string { |
no test coverage detected