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(
9696function renderHighlight(md: MarkdownRenderer) {
9797 const original = md.render.bind(md)
9898 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) => {
100101 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>`
102109 })
103110 return original(replaced, env)
104111 }
docs/.vitepress/theme/components/Highlight.vue +20 −2
@@ -1,6 +1,7 @@
11<template>
2 <span class="highlight-pill" :class="variant">
2 <span class="highlight-pill" :class="[variant, { 'has-link': linked }]">
33 <slot />
4 <span v-if="linked" class="i-mdi-arrow-top-right-thick link-icon"></span>
45 </span>
56</template>
67
@@ -9,6 +10,10 @@ defineProps({
910 variant: {
1011 type: String,
1112 default: 'default'
13 },
14 linked: {
15 type: String,
16 default: null
1217 }
1318})
1419</script>
@@ -16,6 +21,7 @@ defineProps({
1621<style scoped>
1722.highlight-pill {
1823 display: inline-block;
24 position: relative;
1925 padding: 0 0.25em;
2026 border-radius: 4px;
2127 font-size: 0.9em;
@@ -26,6 +32,10 @@ defineProps({
2632 border: 1px solid;
2733}
2834
35.has-link {
36 margin-right: 0.5em;
37}
38
2939.default {
3040 background-color: #042a20;
3141 color: #a8f0cc;
@@ -33,7 +43,7 @@ defineProps({
3343}
3444
3545.warning {
36 background-color: #413306;
46 background-color: #86680e;
3747 color: #fee38b;
3848 border-color: #86680e;
3949}
@@ -43,4 +53,12 @@ defineProps({
4353 color: #fec8c8;
4454 border-color: #981b1b;
4555}
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}
4664</style>
\ No newline at end of file