Commit a8ec027c83

a8ec027c83ab6c7ee994ad7a95fa6149d31ceb0e

parent: a18025f2d1

Unsigned

Duck <57977673+woducku@users.noreply.github.com> · 2026-05-12 08:07 UTC

Add Highlight

Layout: unified · split

docs/.vitepress/configs/markdown/index.ts +12
@@ -39,6 +39,7 @@ export function configureMarkdown(md: MarkdownRenderer) {
39 renderTooltip(md) 39 renderTooltip(md)
40 renderInlineTooltip(md) 40 renderInlineTooltip(md)
41 md.use(markdownSteps) 41 md.use(markdownSteps)
42 renderHighlight(md)
42} 43}
43 44
44function renderInlineTooltip(md: MarkdownRenderer) { 45function renderInlineTooltip(md: MarkdownRenderer) {
@@ -91,3 +92,14 @@ function span(
91 html += `>${content}</span>` 92 html += `>${content}</span>`
92 return html 93 return html
93} 94}
95
96function renderHighlight(md: MarkdownRenderer) {
97 const original = md.render.bind(md)
98 md.render = (src, env) => {
99 const replaced = src.replace(/([!x]?)\|\|(.+?)\|\|/g, (_, prefix, cont) => {
100 const variant = prefix === '!' ? 'warning' : prefix === 'x' ? 'danger' : 'default'
101 return `<hl variant="${variant}">${cont}</hl>`
102 })
103 return original(replaced, env)
104 }
105}\ No newline at end of file
docs/.vitepress/theme/components/Highlight.vue added +46
@@ -0,0 +1,46 @@
1<template>
2 <span class="highlight-pill" :class="variant">
3 <slot />
4 </span>
5</template>
6
7<script setup>
8defineProps({
9 variant: {
10 type: String,
11 default: 'default'
12 }
13})
14</script>
15
16<style scoped>
17.highlight-pill {
18 display: inline-block;
19 padding: 0 0.25em;
20 border-radius: 4px;
21 font-size: 0.9em;
22 font-weight: 500;
23 line-height: 1.5;
24 white-space: nowrap;
25 vertical-align: baseline;
26 border: 1px solid;
27}
28
29.default {
30 background-color: #042a20;
31 color: #a8f0cc;
32 border-color: #0a5c42;
33}
34
35.warning {
36 background-color: #413306;
37 color: #fee38b;
38 border-color: #86680e;
39}
40
41.danger {
42 background-color: #430a0a;
43 color: #fec8c8;
44 border-color: #981b1b;
45}
46</style>\ No newline at end of file
docs/.vitepress/theme/index.ts +3 −1
@@ -26,6 +26,7 @@ import './styles/tooltip-hint.css'
26import './styles/steps.css' 26import './styles/steps.css'
27import Block from './components/Block.vue' 27import Block from './components/Block.vue'
28import LinkInline from './components/LinkInline.vue' 28import LinkInline from './components/LinkInline.vue'
29import Highlight from './components/Highlight.vue'
29 30
30export default { 31export default {
31 extends: DefaultTheme, 32 extends: DefaultTheme,
@@ -48,6 +49,7 @@ export default {
48 }) 49 })
49 enhanceAppWithTabs(app) 50 enhanceAppWithTabs(app)
50 app.component('LinkInline', LinkInline) 51 app.component('LinkInline', LinkInline)
52 app.component('hl', Highlight)
51 app.component('Block', Block) 53 app.component('Block', Block)
52 app.component('Authors', Authors) 54 app.component('Authors', Authors)
53 app.component('Tooltip', Tooltip) 55 app.component('Tooltip', Tooltip)
@@ -103,4 +105,4 @@ export default {
103 ] 105 ]
104 ) 106 )
105 } 107 }
106} satisfies Theme 108} satisfies Theme\ No newline at end of file