From 404e5a465da057f4282be06fb3d0e8bd23384c16 Mon Sep 17 00:00:00 2001 From: ZTL-UwU Date: Tue, 19 Nov 2024 17:35:32 +0800 Subject: [PATCH] feat: code block line numbers Signed-off-by: ZTL-UwU --- components/content/ProseCode.vue | 19 +++++++++++++++++-- components/content/ProsePre.vue | 8 +++++++- content/2.components/1.prose.md | 12 ++++++++++++ 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/components/content/ProseCode.vue b/components/content/ProseCode.vue index b9cc5cb5..eca3aa7a 100644 --- a/components/content/ProseCode.vue +++ b/components/content/ProseCode.vue @@ -19,7 +19,11 @@
@@ -58,8 +62,14 @@ const props = defineProps({ type: Array as () => number[], default: () => [], }, + meta: { + type: String, + default: null, + }, }); +const showLineNumber = computed(() => props.meta.includes('line-numbers')); + const iconMap = new Map(Object.entries(useConfig().value.main.codeIcon)); const icon = iconMap.get(props.filename?.toLowerCase()) || iconMap.get(props.language); @@ -75,7 +85,7 @@ const icon = iconMap.get(props.filename?.toLowerCase()) || iconMap.get(props.lan } .shiki .line.highlight { - background-color: hsl(var(--muted) / 0.8); + background-color: hsl(var(--muted) / 0.9); } .shiki .line { @@ -86,4 +96,9 @@ const icon = iconMap.get(props.filename?.toLowerCase()) || iconMap.get(props.lan .inline-copy .line { padding-right: 2.75rem; } + +.show-line-number .line::before { + content: attr(line); + @apply text-sm w-5 inline-block text-right mr-4 text-muted-foreground; +} diff --git a/components/content/ProsePre.vue b/components/content/ProsePre.vue index d787d79e..ee7a243c 100644 --- a/components/content/ProsePre.vue +++ b/components/content/ProsePre.vue @@ -1,5 +1,11 @@ diff --git a/content/2.components/1.prose.md b/content/2.components/1.prose.md index b21dff20..0a31b4b3 100644 --- a/content/2.components/1.prose.md +++ b/content/2.components/1.prose.md @@ -71,6 +71,12 @@ icon: lucide:letter-text console.log('Code block'); }; ``` + + ```ts{1} [Line Numbers] line-numbers + // line-numbers is enabled + const line2 = 'This is line 2'; + const line3 = 'This is line 3'; + ``` :: ````md [Code] @@ -91,6 +97,12 @@ icon: lucide:letter-text console.log('Code block'); }; ``` + + ```ts{1} [Line Numbers] line-numbers + // line-numbers is enabled + const line2 = 'This is line 2'; + const line3 = 'This is line 3'; + ``` ```` ::