Commit eba2b2a9e0

eba2b2a9e05bf7f920fe725fb457baec730cc763

parent: 92ee7baf0e

Unsigned

Duck <57977673+woducku@users.noreply.github.com> · 2026-06-30 05:46 UTC

fixes

Layout: unified · split

docs/.vitepress/configs/markdown/index.ts +4 −1
@@ -15,6 +15,7 @@ import { imgSize } from '@mdit/plugin-img-size'
1515import MdReg from 'markdown-it-regexp'
1616import type { MarkdownRenderer } from 'vitepress'
1717import {
18 getCollapsibleHeadingAnchor,
1819 getTabAnchor,
1920 getTabHeadingAnchor,
2021 getUniqueAnchor,
@@ -259,7 +260,9 @@ function injectSearchHeadings(src: string) {
259260 '',
260261 `${indent}${
261262 '#'.repeat(headingLevel)
262 } ${headingTitle} {.collapsible-search-heading}`,
263 } ${headingTitle} {#${
264 getCollapsibleHeadingAnchor(collapsibleAnchor)
265 } .collapsible-search-heading}`,
263266 ''
264267 )
265268 i += 3
docs/.vitepress/plugins/urlSearchPlugin.ts +9 −1
@@ -2,8 +2,10 @@ import { writeFileSync } from 'node:fs'
22import { join } from 'node:path'
33import { renderEmojiShortcodes } from '../configs/markdown/emoji'
44import {
5 getCollapsibleHeadingAnchor,
56 getTabAnchor,
67 getTabHeadingAnchor,
8 getUniqueAnchor,
79 parseTabLabel,
810 slugifyAnchor,
911 stripHeadingMarkup
@@ -39,6 +41,7 @@ function extractSearchMetadataFromMarkdown(
3941 const headingStack: string[] = []
4042 const slugCounts = new Map<string, number>()
4143 const tabAnchorCounts = new Map<string, number>()
44 const collapsibleAnchorCounts = new Map<string, number>()
4245 const containerStack: string[] = []
4346 const tabPath: string[] = []
4447 const tabResetStack: {
@@ -164,6 +167,10 @@ function extractSearchMetadataFromMarkdown(
164167 headings: [...headingStack]
165168 })
166169
170 const parsed = parseTabLabel(collapsibleMatch[2])
171 const collapsibleAnchor = parsed.anchor ||
172 getUniqueAnchor(parsed.label, collapsibleAnchorCounts)
173
167174 let nextLine = i + 1
168175 while (nextLine < lines.length && lines[nextLine].trim() === '') {
169176 nextLine++
@@ -175,7 +182,8 @@ function extractSearchMetadataFromMarkdown(
175182 if (!/^#{1,6}\s+/.test(lines[nextLine]?.trim() ?? '')) {
176183 setHeading(
177184 containerStack.includes('tabs') ? 3 : 2,
178 collapsibleMatch[2].trim()
185 parsed.label,
186 getCollapsibleHeadingAnchor(collapsibleAnchor)
179187 )
180188 }
181189 continue
docs/.vitepress/theme/Layout.vue +1 −3
@@ -539,9 +539,7 @@ const tryOpenAnchoredContent = async () => {
539539 return
540540 }
541541
542 if (
543 !requestedTabs.length && target.classList.contains('tab-search-heading')
544 ) {
542 if (target.classList.contains('tab-search-heading')) {
545543 const tabs = target.closest<HTMLElement>('.plugin-tabs')
546544 if (tabs) {
547545 window.history.replaceState(
docs/.vitepress/theme/components/Search.vue +18 −4
@@ -1580,10 +1580,24 @@ onKeyStroke('Tab', (event) => {
15801580const router = useRouter()
15811581
15821582function buildResultHref(pageId: string, tabs?: string[], anchor = '') {
1583 const query = tabs?.length
1584 ? `?tabs=${tabs.map((tab) => encodeURIComponent(tab)).join(',')}`
1585 : ''
1586 const hash = anchor ? `#${encodeURIComponent(anchor)}` : ''
1583 const params: string[] = []
1584 if (tabs?.length) {
1585 params.push(`tabs=${tabs.map((tab) => encodeURIComponent(tab)).join(',')}`)
1586 }
1587
1588 let hash = ''
1589 if (anchor.startsWith('collapsible-')) {
1590 const collapsible = anchor.slice('collapsible-'.length)
1591 if (collapsible) params.push(`c=${encodeURIComponent(collapsible)}`)
1592 } else {
1593 const lastTab = tabs?.length ? tabs[tabs.length - 1] : ''
1594 const isRedundantTabHeading = Boolean(anchor) && anchor === `tab-${lastTab}`
1595 if (anchor && !isRedundantTabHeading) {
1596 hash = `#${encodeURIComponent(anchor)}`
1597 }
1598 }
1599
1600 const query = params.length ? `?${params.join('&')}` : ''
15871601 return `${pageId}${query}${hash}`
15881602}
15891603
docs/.vitepress/utils/tabAnchors.ts +4
@@ -59,3 +59,7 @@ export function getTabAnchor(
5959export function getTabHeadingAnchor(tabAnchor: string) {
6060 return `tab-${tabAnchor}`
6161}
62
63export function getCollapsibleHeadingAnchor(collapsibleAnchor: string) {
64 return `collapsible-${collapsibleAnchor}`
65}