Commit e579b625b2
e579b625b2a45a7bf0bc45639bfb54b7851583d3
parent: a426266132
Unsigned
Duck <57977673+woducku@users.noreply.github.com> · 2026-06-09 13:13 UTC
search fixes for nested collapsible
Layout: unified · split
docs/.vitepress/configs/markdown/index.ts
+4 −1
| @@ -229,12 +229,15 @@ function injectSearchHeadings(src: string) { |
| 229 | 229 | const [, indent, , title] = match |
| 230 | 230 | const headingTitle = title.trim() |
| 231 | 231 | if (!headingTitle) continue |
| 232 | const headingLevel = containerStack.includes('tabs') ? 4 : 3 |
| 232 | 233 | |
| 233 | 234 | lines.splice( |
| 234 | 235 | i + 1, |
| 235 | 236 | 0, |
| 236 | 237 | '', |
| 237 | | `${indent}### ${headingTitle} {.collapsible-search-heading}`, |
| 238 | `${indent}${ |
| 239 | '#'.repeat(headingLevel) |
| 240 | } ${headingTitle} {.collapsible-search-heading}`, |
| 238 | 241 | '' |
| 239 | 242 | ) |
| 240 | 243 | i += 3 |
docs/.vitepress/plugins/urlSearchPlugin.ts
+7 −4
| @@ -102,11 +102,14 @@ function extractLinksFromMarkdown(src: string, pageId: string): PageLink[] { |
| 102 | 102 | nextLine++ |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | | // The markdown renderer injects a searchable H3 for collapsibles that |
| 106 | | // don't already start with a heading. Mirror that anchor so URL search |
| 107 | | // can deep-link into and auto-open those collapsibles. |
| 105 | // The markdown renderer injects searchable headings for collapsibles |
| 106 | // that don't already start with a heading. Mirror that anchor so URL |
| 107 | // search can deep-link into and auto-open those collapsibles. |
| 108 | 108 | if (!/^#{1,6}\s+/.test(lines[nextLine]?.trim() ?? '')) { |
| 109 | | setHeading(2, collapsibleMatch[2].trim()) |
| 109 | setHeading( |
| 110 | containerStack.includes('tabs') ? 3 : 2, |
| 111 | collapsibleMatch[2].trim() |
| 112 | ) |
| 110 | 113 | } |
| 111 | 114 | continue |
| 112 | 115 | } |
docs/.vitepress/theme/Layout.vue
+16 −7
| @@ -257,8 +257,14 @@ const selectTabContainingQuery = async (target: HTMLElement, query: string) => { |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | const openCollapsibles = async (target: HTMLElement) => { |
| 260 | | let scrollTarget = getScrollTargetForAnchor(target) |
| 261 | | let el: HTMLElement | null = target |
| 260 | await selectTabContainingQuery(target, searchQuery) |
| 261 | await nextTick() |
| 262 | await nextFrame() |
| 263 | |
| 264 | const hashTarget = getTargetByHash(window.location.hash.slice(1)) |
| 265 | const activeTarget = hashTarget ?? target |
| 266 | let scrollTarget = getScrollTargetForAnchor(activeTarget) |
| 267 | let el: HTMLElement | null = activeTarget |
| 262 | 268 | |
| 263 | 269 | while ((el = el.closest('details'))) { |
| 264 | 270 | el.open = true |
| @@ -266,7 +272,7 @@ const openCollapsibles = async (target: HTMLElement) => { |
| 266 | 272 | el = el.parentElement |
| 267 | 273 | } |
| 268 | 274 | |
| 269 | | const tagName = target.tagName |
| 275 | const tagName = activeTarget.tagName |
| 270 | 276 | if (tagName.length === 2 && tagName[0] === 'H') { |
| 271 | 277 | const level = +tagName[1] |
| 272 | 278 | if (level >= 1 && level <= 6) { |
| @@ -277,7 +283,7 @@ const openCollapsibles = async (target: HTMLElement) => { |
| 277 | 283 | return terms.every((term) => text.includes(term)) |
| 278 | 284 | } |
| 279 | 285 | |
| 280 | | let sibling = target.nextElementSibling |
| 286 | let sibling = activeTarget.nextElementSibling |
| 281 | 287 | |
| 282 | 288 | while (sibling) { |
| 283 | 289 | const siblingTag = sibling.tagName |
| @@ -289,7 +295,9 @@ const openCollapsibles = async (target: HTMLElement) => { |
| 289 | 295 | if (siblingTag === 'DETAILS') { |
| 290 | 296 | if (detailsContainsTerms(sibling as HTMLElement)) { |
| 291 | 297 | ;(sibling as HTMLDetailsElement).open = true |
| 292 | | if (scrollTarget === target) scrollTarget = sibling as HTMLElement |
| 298 | if (scrollTarget === activeTarget) { |
| 299 | scrollTarget = sibling as HTMLElement |
| 300 | } |
| 293 | 301 | } |
| 294 | 302 | } |
| 295 | 303 | |
| @@ -297,7 +305,7 @@ const openCollapsibles = async (target: HTMLElement) => { |
| 297 | 305 | for (let i = 0, len = nested.length; i < len; i++) { |
| 298 | 306 | if (detailsContainsTerms(nested[i])) { |
| 299 | 307 | nested[i].open = true |
| 300 | | if (scrollTarget === target) scrollTarget = nested[i] |
| 308 | if (scrollTarget === activeTarget) scrollTarget = nested[i] |
| 301 | 309 | } |
| 302 | 310 | } |
| 303 | 311 | |
| @@ -306,7 +314,8 @@ const openCollapsibles = async (target: HTMLElement) => { |
| 306 | 314 | } |
| 307 | 315 | } |
| 308 | 316 | |
| 309 | | await selectTabContainingQuery(target, searchQuery) |
| 317 | await nextTick() |
| 318 | await nextFrame() |
| 310 | 319 | |
| 311 | 320 | scrollToElement(scrollTarget) |
| 312 | 321 | } |