Commit 9686eeffa7

9686eeffa7d678e248c1cda50261ec6d399ae877

parent: 8360448ae1

Unsigned

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

Link indicator for highlight component

Layout: unified · split

docs/.vitepress/configs/markdown/index.ts +9 −2
@@ -96,9 +96,16 @@ function span(
96function renderHighlight(md: MarkdownRenderer) { 96function renderHighlight(md: MarkdownRenderer) {
97 const original = md.render.bind(md) 97 const original = md.render.bind(md)
98 md.render = (src, env) => { 98 md.render = (src, env) => {
99 const replaced = src.replace(/([!x]?)\|\|(.+?)\|\|/g, (_, prefix, cont) => { 99 // Replace [||text||](url) — linked pill
100 let replaced = src.replace(/\[([!x]?)\|\|(.+?)\|\|\]\((.+?)\)/g, (_, prefix, cont, url) => {
100 const variant = prefix === '!' ? 'warning' : prefix === 'x' ? 'danger' : 'default' 101 const variant = prefix === '!' ? 'warning' : prefix === 'x' ? 'danger' : 'default'
101 return `<hl variant="${variant}">${cont}</hl>` 102 const inner = md.renderInline(cont, env)
103 return `<a href="${url}" target="_blank" rel="noopener noreferrer"><hl variant="${variant}" linked="true">${inner}</hl></a>`
104 })
105 // Replace standalone ||text||
106 replaced = replaced.replace(/([!x]?)\|\|(.+?)\|\|/g, (_, prefix, cont) => {
107 const variant = prefix === '!' ? 'warning' : prefix === 'x' ? 'danger' : 'default'
108 return `<hl variant="${variant}">${md.renderInline(cont, env)}</hl>`
102 }) 109 })
103 return original(replaced, env) 110 return original(replaced, env)
104 } 111 }
docs/.vitepress/theme/components/Highlight.vue +20 −2
@@ -1,6 +1,7 @@
1<template> 1<template>
2 <span class="highlight-pill" :class="variant"> 2 <span class="highlight-pill" :class="[variant, { 'has-link': linked }]">
3 <slot /> 3 <slot />
4 <span v-if="linked" class="i-mdi-arrow-top-right-thick link-icon"></span>
4 </span> 5 </span>
5</template> 6</template>
6 7
@@ -9,6 +10,10 @@ defineProps({
9 variant: { 10 variant: {
10 type: String, 11 type: String,
11 default: 'default' 12 default: 'default'
13 },
14 linked: {
15 type: String,
16 default: null
12 } 17 }
13}) 18})
14</script> 19</script>
@@ -16,6 +21,7 @@ defineProps({
16<style scoped> 21<style scoped>
17.highlight-pill { 22.highlight-pill {
18 display: inline-block; 23 display: inline-block;
24 position: relative;
19 padding: 0 0.25em; 25 padding: 0 0.25em;
20 border-radius: 4px; 26 border-radius: 4px;
21 font-size: 0.9em; 27 font-size: 0.9em;
@@ -26,6 +32,10 @@ defineProps({
26 border: 1px solid; 32 border: 1px solid;
27} 33}
28 34
35.has-link {
36 margin-right: 0.5em;
37}
38
29.default { 39.default {
30 background-color: #042a20; 40 background-color: #042a20;
31 color: #a8f0cc; 41 color: #a8f0cc;
@@ -33,7 +43,7 @@ defineProps({
33} 43}
34 44
35.warning { 45.warning {
36 background-color: #413306; 46 background-color: #86680e;
37 color: #fee38b; 47 color: #fee38b;
38 border-color: #86680e; 48 border-color: #86680e;
39} 49}
@@ -43,4 +53,12 @@ defineProps({
43 color: #fec8c8; 53 color: #fec8c8;
44 border-color: #981b1b; 54 border-color: #981b1b;
45} 55}
56
57.link-icon {
58 position: absolute;
59 top: -0.65em;
60 right: -0.8em;
61 font-size: 0.9em;
62 opacity: 0.9;
63}
46</style>\ No newline at end of file 64</style>\ No newline at end of file