Commit 0f5cac550d
Unsigned
Layout: unified · split
docs/.vitepress/plugins/urlSearchPlugin.ts +13 −16
| @@ -57,9 +57,7 @@ function isDelimiterRow(line: string): boolean { | ||
| 57 | 57 | |
| 58 | 58 | const isMoreMarker = (line: string) => /^<more\s*\/?>$/i.test(line.trim()) |
| 59 | 59 | |
| 60 | // Find `<more>` table blocks and their `data-table-more` anchors in | |
| 61 | // document order, mirroring tableMorePlugin: the marker must directly | |
| 62 | // follow a (delimiter-row) table and hidden rows must follow the marker. | |
| 60 | // Find `data-table-more` anchors in document order (mirrors tableMorePlugin). | |
| 63 | 61 | function findTableMoreBlocks(lines: string[]): TableMoreBlock[] { |
| 64 | 62 | const blocks: TableMoreBlock[] = [] |
| 65 | 63 | const n = lines.length |
| @@ -71,7 +69,7 @@ function findTableMoreBlocks(lines: string[]): TableMoreBlock[] { | ||
| 71 | 69 | i++ |
| 72 | 70 | continue |
| 73 | 71 | } |
| 74 | // Walk back over blanks: must sit directly after a table run. | |
| 72 | // Marker must directly follow a table run. | |
| 75 | 73 | let t = i - 1 |
| 76 | 74 | while (t >= 0 && lines[t].trim() === '') t-- |
| 77 | 75 | if (t < 0 || !isPipeLine(lines[t])) { |
| @@ -91,7 +89,7 @@ function findTableMoreBlocks(lines: string[]): TableMoreBlock[] { | ||
| 91 | 89 | i++ |
| 92 | 90 | continue |
| 93 | 91 | } |
| 94 | // Hidden rows after the marker: bare pipe lines or a full table. | |
| 92 | // Hidden rows: bare pipe lines or a full table. | |
| 95 | 93 | let h = i + 1 |
| 96 | 94 | while (h < n && lines[h].trim() === '') h++ |
| 97 | 95 | let hiddenEnd = -1 |
| @@ -99,7 +97,7 @@ function findTableMoreBlocks(lines: string[]): TableMoreBlock[] { | ||
| 99 | 97 | if ( |
| 100 | 98 | h + 1 < n && isPipeLine(lines[h + 1]) && isDelimiterRow(lines[h + 1]) |
| 101 | 99 | ) { |
| 102 | // Full second table: needs at least one body row. | |
| 100 | // Full second table needs a body row. | |
| 103 | 101 | if (h + 2 < n && isPipeLine(lines[h + 2])) { |
| 104 | 102 | let e = h + 2 |
| 105 | 103 | while (e + 1 < n && isPipeLine(lines[e + 1])) e++ |
| @@ -153,7 +151,7 @@ function extractSearchMetadataFromMarkdown( | ||
| 153 | 151 | |
| 154 | 152 | const getMirrorUrls = (id: string) => { |
| 155 | 153 | if (mirrorCache.has(id)) return mirrorCache.get(id) |
| 156 | // Direct URL form: ==m:https://example.com/== (no mirror file needed) | |
| 154 | // Direct URL form needs no mirror file. | |
| 157 | 155 | if (/^https?:\/\/\S+$/i.test(id)) { |
| 158 | 156 | let title = id |
| 159 | 157 | try { |
| @@ -254,9 +252,7 @@ function extractSearchMetadataFromMarkdown( | ||
| 254 | 252 | const getTabsDepth = () => |
| 255 | 253 | containerStack.filter((name) => name === 'tabs').length |
| 256 | 254 | |
| 257 | // Mirror-part-1 helper: table-more (`<more>`) blocks in document order. | |
| 258 | // Anchor numbers must match the renderer's `data-table-more` counter, | |
| 259 | // which stamps qualifying blocks sequentially in a single page render. | |
| 255 | // Anchors must match the renderer `data-table-more` counter. | |
| 260 | 256 | const tableMoreBlocks = findTableMoreBlocks(lines) |
| 261 | 257 | |
| 262 | 258 | const tablesForLine = (idx: number): string[] => { |
| @@ -362,8 +358,7 @@ function extractSearchMetadataFromMarkdown( | ||
| 362 | 358 | tabPath[depth - 1] = anchor |
| 363 | 359 | tabPath.length = depth |
| 364 | 360 | |
| 365 | // The markdown renderer injects a hidden H3 for each tab label. | |
| 366 | // Mirror that heading so search can deep-link to the selected tab. | |
| 361 | // Mirror injected tab headings for deep-linking. | |
| 367 | 362 | setHeading(2, parsed.label, headingAnchor) |
| 368 | 363 | } |
| 369 | 364 | continue |
| @@ -387,9 +382,7 @@ function extractSearchMetadataFromMarkdown( | ||
| 387 | 382 | nextLine++ |
| 388 | 383 | } |
| 389 | 384 | |
| 390 | // The markdown renderer injects searchable headings for collapsibles | |
| 391 | // that don't already start with a heading. Mirror that anchor so URL | |
| 392 | // search can deep-link into and auto-open those collapsibles. | |
| 385 | // Mirror injected collapsible headings for deep-linking. | |
| 393 | 386 | if (!/^#{1,6}\s+/.test(lines[nextLine]?.trim() ?? '')) { |
| 394 | 387 | setHeading( |
| 395 | 388 | containerStack.includes('tabs') ? 3 : 2, |
| @@ -433,9 +426,13 @@ function extractSearchMetadataFromMarkdown( | ||
| 433 | 426 | const mirror = getMirrorUrls(id) |
| 434 | 427 | if (!mirror) continue |
| 435 | 428 | const label = getMirrorMainLabel(line, mirror.title) |
| 429 | const srcNorm = mirror.src.trim() | |
| 436 | 430 | for (const href of [mirror.src, ...mirror.mirrors]) { |
| 437 | 431 | if (!href) continue |
| 438 | pushLink(href.trim(), label, i, { mirror: id }) | |
| 432 | const h = href.trim() | |
| 433 | // File src is the normal link; only mirrors get flagged. | |
| 434 | const isMainSrc = mirror.mirrors.length > 0 && h === srcNorm | |
| 435 | pushLink(h, label, i, isMainSrc ? undefined : { mirror: id }) | |
| 439 | 436 | } |
| 440 | 437 | } |
| 441 | 438 | } |