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) {
3939 renderTooltip(md)
4040 renderInlineTooltip(md)
4141 md.use(markdownSteps)
42 renderHighlight(md)
4243}
4344
4445function renderInlineTooltip(md: MarkdownRenderer) {
@@ -91,3 +92,14 @@ function span(
9192 html += `>${content}</span>`
9293 return html
9394}
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'
2626import './styles/steps.css'
2727import Block from './components/Block.vue'
2828import LinkInline from './components/LinkInline.vue'
29import Highlight from './components/Highlight.vue'
2930
3031export default {
3132 extends: DefaultTheme,
@@ -48,6 +49,7 @@ export default {
4849 })
4950 enhanceAppWithTabs(app)
5051 app.component('LinkInline', LinkInline)
52 app.component('hl', Highlight)
5153 app.component('Block', Block)
5254 app.component('Authors', Authors)
5355 app.component('Tooltip', Tooltip)
@@ -103,4 +105,4 @@ export default {
103105 ]
104106 )
105107 }
106} satisfies Theme
108} satisfies Theme
\ No newline at end of file