Commit 0f5cac550d

0f5cac550d6b5180b865b8655c1752e08ec79efa

parent: dc491573aa

Unsigned

Duck <57977673+woducku@users.noreply.github.com> · 2026-09-26 06:33 UTC

Update urlSearchPlugin.ts

Layout: unified · split

docs/.vitepress/plugins/urlSearchPlugin.ts +13 −16
@@ -57,9 +57,7 @@ function isDelimiterRow(line: string): boolean {
5757
5858const isMoreMarker = (line: string) => /^<more\s*\/?>$/i.test(line.trim())
5959
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).
6361function findTableMoreBlocks(lines: string[]): TableMoreBlock[] {
6462 const blocks: TableMoreBlock[] = []
6563 const n = lines.length
@@ -71,7 +69,7 @@ function findTableMoreBlocks(lines: string[]): TableMoreBlock[] {
7169 i++
7270 continue
7371 }
74 // Walk back over blanks: must sit directly after a table run.
72 // Marker must directly follow a table run.
7573 let t = i - 1
7674 while (t >= 0 && lines[t].trim() === '') t--
7775 if (t < 0 || !isPipeLine(lines[t])) {
@@ -91,7 +89,7 @@ function findTableMoreBlocks(lines: string[]): TableMoreBlock[] {
9189 i++
9290 continue
9391 }
94 // Hidden rows after the marker: bare pipe lines or a full table.
92 // Hidden rows: bare pipe lines or a full table.
9593 let h = i + 1
9694 while (h < n && lines[h].trim() === '') h++
9795 let hiddenEnd = -1
@@ -99,7 +97,7 @@ function findTableMoreBlocks(lines: string[]): TableMoreBlock[] {
9997 if (
10098 h + 1 < n && isPipeLine(lines[h + 1]) && isDelimiterRow(lines[h + 1])
10199 ) {
102 // Full second table: needs at least one body row.
100 // Full second table needs a body row.
103101 if (h + 2 < n && isPipeLine(lines[h + 2])) {
104102 let e = h + 2
105103 while (e + 1 < n && isPipeLine(lines[e + 1])) e++
@@ -153,7 +151,7 @@ function extractSearchMetadataFromMarkdown(
153151
154152 const getMirrorUrls = (id: string) => {
155153 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.
157155 if (/^https?:\/\/\S+$/i.test(id)) {
158156 let title = id
159157 try {
@@ -254,9 +252,7 @@ function extractSearchMetadataFromMarkdown(
254252 const getTabsDepth = () =>
255253 containerStack.filter((name) => name === 'tabs').length
256254
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.
260256 const tableMoreBlocks = findTableMoreBlocks(lines)
261257
262258 const tablesForLine = (idx: number): string[] => {
@@ -362,8 +358,7 @@ function extractSearchMetadataFromMarkdown(
362358 tabPath[depth - 1] = anchor
363359 tabPath.length = depth
364360
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.
367362 setHeading(2, parsed.label, headingAnchor)
368363 }
369364 continue
@@ -387,9 +382,7 @@ function extractSearchMetadataFromMarkdown(
387382 nextLine++
388383 }
389384
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.
393386 if (!/^#{1,6}\s+/.test(lines[nextLine]?.trim() ?? '')) {
394387 setHeading(
395388 containerStack.includes('tabs') ? 3 : 2,
@@ -433,9 +426,13 @@ function extractSearchMetadataFromMarkdown(
433426 const mirror = getMirrorUrls(id)
434427 if (!mirror) continue
435428 const label = getMirrorMainLabel(line, mirror.title)
429 const srcNorm = mirror.src.trim()
436430 for (const href of [mirror.src, ...mirror.mirrors]) {
437431 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 })
439436 }
440437 }
441438 }