Commit e64713b578

e64713b57884b1270caf68db2ea771e5901e0858

parent: 947b36e062

Unsigned

taskylizard <75871323+taskylizard@users.noreply.github.com> · 2026-05-29 13:18 UTC

add invisible headings for search

Layout: unified · split

docs/.vitepress/configs/markdown/index.ts +54 −8
@@ -18,8 +18,8 @@ import { tabsMarkdownPlugin } from 'vitepress-plugin-tabs'
1818import { getTooltip } from '../../utils/tooltips'
1919import { headersPlugin } from '../markdown/headers'
2020import { emojiRender } from './emoji'
21import markdownSteps from './steps'
2221import { scrapeTablePlugin } from './scrapeTablePlugin'
22import markdownSteps from './steps'
2323
2424export function configureMarkdown(md: MarkdownRenderer) {
2525 md.use(emojiRender)
@@ -98,17 +98,63 @@ function span(
9898function renderHighlight(md: MarkdownRenderer) {
9999 const original = md.render.bind(md)
100100 md.render = (src, env) => {
101 const withCollapsibleHeadings = injectCollapsibleSearchHeadings(src)
102
101103 // Replace [||text||](url) — linked pill
102 let replaced = src.replace(/\[([!x]?)\|\|(.+?)\|\|\]\((.+?)\)/g, (_, prefix, cont, url) => {
103 const variant = prefix === '!' ? 'warning' : prefix === 'x' ? 'danger' : 'default'
104 const inner = md.renderInline(cont, env)
105 return `<a href="${url}" target="_blank" rel="noopener noreferrer"><hl variant="${variant}" linked="true">${inner}</hl></a>`
106 })
104 let replaced = withCollapsibleHeadings.replace(
105 /\[([!x]?)\|\|(.+?)\|\|\]\((.+?)\)/g,
106 (_, prefix, cont, url) => {
107 const variant = prefix === '!'
108 ? 'warning'
109 : prefix === 'x'
110 ? 'danger'
111 : 'default'
112 const inner = md.renderInline(cont, env)
113 return `<a href="${url}" target="_blank" rel="noopener noreferrer"><hl variant="${variant}" linked="true">${inner}</hl></a>`
114 }
115 )
107116 // Replace standalone ||text||
108117 replaced = replaced.replace(/([!x]?)\|\|(.+?)\|\|/g, (_, prefix, cont) => {
109 const variant = prefix === '!' ? 'warning' : prefix === 'x' ? 'danger' : 'default'
118 const variant = prefix === '!'
119 ? 'warning'
120 : prefix === 'x'
121 ? 'danger'
122 : 'default'
110123 return `<hl variant="${variant}">${md.renderInline(cont, env)}</hl>`
111124 })
112125 return original(replaced, env)
113126 }
114}
\ No newline at end of file
127}
128
129function injectCollapsibleSearchHeadings(src: string) {
130 const lines = src.split('\n')
131
132 for (let i = 0; i < lines.length; i++) {
133 const match = lines[i].match(
134 /^(\s*)<Collapsible\b(?=[^>]*\btitle=(['"])(.*?)\2)[^>]*>\s*$/i
135 )
136 if (!match) continue
137
138 let nextLine = i + 1
139 while (nextLine < lines.length && lines[nextLine].trim() === '') {
140 nextLine++
141 }
142
143 if (/^#{1,6}\s+/.test(lines[nextLine]?.trim() ?? '')) continue
144
145 const [, indent, , title] = match
146 const headingTitle = title.trim()
147 if (!headingTitle) continue
148
149 lines.splice(
150 i + 1,
151 0,
152 '',
153 `${indent}### ${headingTitle} {.collapsible-search-heading}`,
154 ''
155 )
156 i += 3
157 }
158
159 return lines.join('\n')
160}
docs/.vitepress/theme/constants.ts −1
@@ -5,7 +5,6 @@ import type { Options } from './types'
55import _VPFlyout from 'vitepress/dist/client/theme-default/components/VPFlyout.vue'
66// @ts-ignore - VitePress doesn't have types for its internal components
77import _VPLocalNavOutlineDropdown from 'vitepress/dist/client/theme-default/components/VPLocalNavOutlineDropdown.vue'
8// Isolate the types of Vitepress internal components to avoid typecheck errors
98export const VPFlyout: any = _VPFlyout
109export const VPLocalNavOutlineDropdown: any = _VPLocalNavOutlineDropdown
1110
docs/.vitepress/theme/styles/style.scss +12 −1
@@ -1648,6 +1648,17 @@ html.reduce-blur-effects {
16481648 border-top: none !important;
16491649}
16501650
1651.vp-doc .collapsible-search-heading {
1652 position: absolute;
1653 width: 1px;
1654 height: 1px;
1655 padding: 0;
1656 margin: -1px;
1657 overflow: hidden;
1658 clip: rect(0, 0, 0, 0);
1659 white-space: nowrap;
1660 border: 0;
1661}
16511662
16521663/* noteblock icon shrinking and top-bottom padding fix */
16531664.vp-doc .custom-block-title {
@@ -1663,4 +1674,4 @@ html.reduce-blur-effects {
16631674
16641675.vp-doc .custom-block {
16651676 padding-bottom: 16px;
1666}
\ No newline at end of file
1677}
package.json −2
@@ -3,7 +3,6 @@
33 "version": "0",
44 "type": "module",
55 "scripts": {
6 "typecheck": "vue-tsc --noEmit",
76 "format": "dprint fmt",
87 "docs:dev": "vitepress dev docs",
98 "docs:build": "NODE_OPTIONS='--max-old-space-size=8192' vitepress build docs",
@@ -53,7 +52,6 @@
5352 "vitepress": "2.0.0-alpha.12",
5453 "vitepress-plugin-tabs": "^0.7.3",
5554 "vue": "^3.5.24",
56 "vue-tsc": "^3.1.3",
5755 "zod": "^4.1.11"
5856 },
5957 "devDependencies": {
pnpm-lock.yaml −71
@@ -125,9 +125,6 @@ importers:
125125 vue:
126126 specifier: ^3.5.24
127127 version: 3.5.24(typescript@5.6.3)
128 vue-tsc:
129 specifier: ^3.1.3
130 version: 3.1.3(typescript@5.6.3)
131128 zod:
132129 specifier: ^4.1.11
133130 version: 4.1.12
@@ -1542,15 +1539,6 @@ packages:
15421539 vite: ^5.0.0 || ^6.0.0 || ^7.0.0
15431540 vue: ^3.2.25
15441541
1545 '@volar/language-core@2.4.23':
1546 resolution: {integrity: sha512-hEEd5ET/oSmBC6pi1j6NaNYRWoAiDhINbT8rmwtINugR39loROSlufGdYMF9TaKGfz+ViGs1Idi3mAhnuPcoGQ==}
1547
1548 '@volar/source-map@2.4.23':
1549 resolution: {integrity: sha512-Z1Uc8IB57Lm6k7q6KIDu/p+JWtf3xsXJqAX/5r18hYOTpJyBn0KXUR8oTJ4WFYOcDzWC9n3IflGgHowx6U6z9Q==}
1550
1551 '@volar/typescript@2.4.23':
1552 resolution: {integrity: sha512-lAB5zJghWxVPqfcStmAP1ZqQacMpe90UrP5RJ3arDyrhy4aCUQqmxPPLB2PWDKugvylmO41ljK7vZ+t6INMTag==}
1553
15541542 '@vue/babel-helper-vue-transform-on@1.5.0':
15551543 resolution: {integrity: sha512-0dAYkerNhhHutHZ34JtTl2czVQHUNWv6xEbkdF5W+Yrv5pCWsqjeORdOgbtW2I9gWlt+wBmVn+ttqN9ZxR5tzA==}
15561544
@@ -1605,14 +1593,6 @@ packages:
16051593 '@vue/devtools-shared@8.0.3':
16061594 resolution: {integrity: sha512-s/QNll7TlpbADFZrPVsaUNPCOF8NvQgtgmmB7Tip6pLf/HcOvBTly0lfLQ0Eylu9FQ4OqBhFpLyBgwykiSf8zw==}
16071595
1608 '@vue/language-core@3.1.3':
1609 resolution: {integrity: sha512-KpR1F/eGAG9D1RZ0/T6zWJs6dh/pRLfY5WupecyYKJ1fjVmDMgTPw9wXmKv2rBjo4zCJiOSiyB8BDP1OUwpMEA==}
1610 peerDependencies:
1611 typescript: '*'
1612 peerDependenciesMeta:
1613 typescript:
1614 optional: true
1615
16161596 '@vue/reactivity@3.5.24':
16171597 resolution: {integrity: sha512-BM8kBhtlkkbnyl4q+HiF5R5BL0ycDPfihowulm02q3WYp2vxgPcJuZO866qa/0u3idbMntKEtVNuAUp5bw4teg==}
16181598
@@ -1774,9 +1754,6 @@ packages:
17741754 resolution: {integrity: sha512-MnA+YT8fwfJPgBx3m60MNqakm30XOkyIoH1y6huTQvC0PwZG7ki8NacLBcrPbNoo8vEZy7Jpuk7+jMO+CUovTQ==}
17751755 engines: {node: '>= 14'}
17761756
1777 alien-signals@3.1.0:
1778 resolution: {integrity: sha512-yufC6VpSy8tK3I0lO67pjumo5JvDQVQyr38+3OHqe6CHl1t2VZekKZ7EKKZSqk0cRmE7U7tfZbpXiKNzuc+ckg==}
1779
17801757 ansi-regex@5.0.1:
17811758 resolution: {integrity: sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==}
17821759 engines: {node: '>=8'}
@@ -2779,9 +2756,6 @@ packages:
27792756 ms@2.1.3:
27802757 resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==}
27812758
2782 muggle-string@0.4.1:
2783 resolution: {integrity: sha512-VNTrAak/KhO2i8dqqnqnAHOa3cYBwXEZe9h+D5h/1ZqFSTEFHdM65lR7RoIqq3tBBYavsOXV84NoHXZ0AkPyqQ==}
2784
27852759 nanoid@3.3.11:
27862760 resolution: {integrity: sha512-N8SpfPUnUp1bK+PMYW8qSWdl9U+wwNWI4QKxOYDy9JAro3WMX7p2OeVRF9v+347pnakNevPmiHhNmZ2HbFA76w==}
27872761 engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1}
@@ -2903,9 +2877,6 @@ packages:
29032877 resolution: {integrity: sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==}
29042878 engines: {node: '>= 0.8'}
29052879
2906 path-browserify@1.0.1:
2907 resolution: {integrity: sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g==}
2908
29092880 path-key@3.1.1:
29102881 resolution: {integrity: sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==}
29112882 engines: {node: '>=8'}
@@ -3654,12 +3625,6 @@ packages:
36543625 peerDependencies:
36553626 vue: ^3.0.0
36563627
3657 vue-tsc@3.1.3:
3658 resolution: {integrity: sha512-StMNfZHwPIXQgY3KxPKM0Jsoc8b46mDV3Fn2UlHCBIwRJApjqrSwqeMYgWf0zpN+g857y74pv7GWuBm+UqQe1w==}
3659 hasBin: true
3660 peerDependencies:
3661 typescript: '>=5.0.0'
3662
36633628 vue@3.5.24:
36643629 resolution: {integrity: sha512-uTHDOpVQTMjcGgrqFPSb8iO2m1DUvo+WbGqoXQz8Y1CeBYQ0FXf2z1gLRaBtHjlRz7zZUBHxjVB5VTLzYkvftg==}
36653630 peerDependencies:
@@ -4996,18 +4961,6 @@ snapshots:
49964961 vite: rolldown-vite@7.2.1(@types/node@22.19.0)(esbuild@0.25.12)(jiti@2.6.1)(less@4.4.2)(sass@1.93.3)(terser@5.44.1)
49974962 vue: 3.5.24(typescript@5.6.3)
49984963
4999 '@volar/language-core@2.4.23':
5000 dependencies:
5001 '@volar/source-map': 2.4.23
5002
5003 '@volar/source-map@2.4.23': {}
5004
5005 '@volar/typescript@2.4.23':
5006 dependencies:
5007 '@volar/language-core': 2.4.23
5008 path-browserify: 1.0.1
5009 vscode-uri: 3.1.0
5010
50114964 '@vue/babel-helper-vue-transform-on@1.5.0': {}
50124965
50134966 '@vue/babel-plugin-jsx@1.5.0(@babel/core@7.28.5)':
@@ -5127,18 +5080,6 @@ snapshots:
51275080 dependencies:
51285081 rfdc: 1.4.1
51295082
5130 '@vue/language-core@3.1.3(typescript@5.6.3)':
5131 dependencies:
5132 '@volar/language-core': 2.4.23
5133 '@vue/compiler-dom': 3.5.24
5134 '@vue/shared': 3.5.24
5135 alien-signals: 3.1.0
5136 muggle-string: 0.4.1
5137 path-browserify: 1.0.1
5138 picomatch: 4.0.3
5139 optionalDependencies:
5140 typescript: 5.6.3
5141
51425083 '@vue/reactivity@3.5.24':
51435084 dependencies:
51445085 '@vue/shared': 3.5.24
@@ -5240,8 +5181,6 @@ snapshots:
52405181
52415182 agent-base@7.1.4: {}
52425183
5243 alien-signals@3.1.0: {}
5244
52455184 ansi-regex@5.0.1: {}
52465185
52475186 ansi-regex@6.2.2: {}
@@ -6189,8 +6128,6 @@ snapshots:
61896128
61906129 ms@2.1.3: {}
61916130
6192 muggle-string@0.4.1: {}
6193
61946131 nanoid@3.3.11: {}
61956132
61966133 nanoid@5.1.6: {}
@@ -6405,8 +6342,6 @@ snapshots:
64056342
64066343 parseurl@1.3.3: {}
64076344
6408 path-browserify@1.0.1: {}
6409
64106345 path-key@3.1.1: {}
64116346
64126347 path-key@4.0.0: {}
@@ -7203,12 +7138,6 @@ snapshots:
72037138 dependencies:
72047139 vue: 3.5.24(typescript@5.6.3)
72057140
7206 vue-tsc@3.1.3(typescript@5.6.3):
7207 dependencies:
7208 '@volar/typescript': 2.4.23
7209 '@vue/language-core': 3.1.3(typescript@5.6.3)
7210 typescript: 5.6.3
7211
72127141 vue@3.5.24(typescript@5.6.3):
72137142 dependencies:
72147143 '@vue/compiler-dom': 3.5.24