Commit 9686eeffa7
Unsigned
Layout: unified · split
docs/.vitepress/configs/markdown/index.ts +9 −2
| @@ -96,9 +96,16 @@ function span( | ||
| 96 | 96 | function renderHighlight(md: MarkdownRenderer) { |
| 97 | 97 | const original = md.render.bind(md) |
| 98 | 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 | 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 | 110 | return original(replaced, env) |
| 104 | 111 | } |
docs/.vitepress/theme/components/Highlight.vue +20 −2
| @@ -1,6 +1,7 @@ | ||
| 1 | 1 | <template> |
| 2 | <span class="highlight-pill" :class="variant"> | |
| 2 | <span class="highlight-pill" :class="[variant, { 'has-link': linked }]"> | |
| 3 | 3 | <slot /> |
| 4 | <span v-if="linked" class="i-mdi-arrow-top-right-thick link-icon"></span> | |
| 4 | 5 | </span> |
| 5 | 6 | </template> |
| 6 | 7 | |
| @@ -9,6 +10,10 @@ defineProps({ | ||
| 9 | 10 | variant: { |
| 10 | 11 | type: String, |
| 11 | 12 | default: 'default' |
| 13 | }, | |
| 14 | linked: { | |
| 15 | type: String, | |
| 16 | default: null | |
| 12 | 17 | } |
| 13 | 18 | }) |
| 14 | 19 | </script> |
| @@ -16,6 +21,7 @@ defineProps({ | ||
| 16 | 21 | <style scoped> |
| 17 | 22 | .highlight-pill { |
| 18 | 23 | display: inline-block; |
| 24 | position: relative; | |
| 19 | 25 | padding: 0 0.25em; |
| 20 | 26 | border-radius: 4px; |
| 21 | 27 | font-size: 0.9em; |
| @@ -26,6 +32,10 @@ defineProps({ | ||
| 26 | 32 | border: 1px solid; |
| 27 | 33 | } |
| 28 | 34 | |
| 35 | .has-link { | |
| 36 | margin-right: 0.5em; | |
| 37 | } | |
| 38 | ||
| 29 | 39 | .default { |
| 30 | 40 | background-color: #042a20; |
| 31 | 41 | color: #a8f0cc; |
| @@ -33,7 +43,7 @@ defineProps({ | ||
| 33 | 43 | } |
| 34 | 44 | |
| 35 | 45 | .warning { |
| 36 | background-color: #413306; | |
| 46 | background-color: #86680e; | |
| 37 | 47 | color: #fee38b; |
| 38 | 48 | border-color: #86680e; |
| 39 | 49 | } |
| @@ -43,4 +53,12 @@ defineProps({ | ||
| 43 | 53 | color: #fec8c8; |
| 44 | 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 | 64 | </style> |
| \ No newline at end of file | ||