Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1e50cfb

Browse files
committed
docs: fix copy block code
1 parent c408262 commit 1e50cfb

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

apps/www/.vitepress/theme/components/BlockViewerCode.vue

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,17 @@ const props = defineProps<{
1313
1414
const activeFile = ref<FileTree>()
1515
16-
const cacheCodes = ref<Map<string, string>>(new Map<string, string>())
17-
const activeCode = computed(() => cacheCodes.value.get(activeFile.value?.path ?? ''))
16+
const cacheCodes = ref<Map<string, { raw: string, html: string }>>(new Map())
17+
const activeFileMeta = computed(() => cacheCodes.value.get(activeFile.value?.path ?? ''))
1818
1919
onBeforeMount(async () => {
2020
for (const file of (props.item.files ?? [])) {
2121
const raw = await file.raw()
2222
const highlighted = highlight(raw, 'vue')
23-
cacheCodes.value.set(file.target || file.path.split(`${props.item.name}/`)[1], highlighted)
23+
cacheCodes.value.set(file.target || file.path.split(`${props.item.name}/`)[1], {
24+
raw,
25+
html: highlighted,
26+
})
2427
}
2528
})
2629
</script>
@@ -35,10 +38,10 @@ onBeforeMount(async () => {
3538
<File class="size-4" />
3639
{{ activeFile?.path }}
3740
<div class="ml-auto flex items-center gap-2">
38-
<BlockCopyCodeButton :code="activeCode" />
41+
<BlockCopyCodeButton :code="activeFileMeta?.raw" />
3942
</div>
4043
</div>
41-
<div :key="activeFile?.path" data-line-codeblock class="relative flex-1 overflow-hidden after:absolute after:inset-y-0 after:left-0 after:w-10 after:bg-zinc-950 [&_.line:before]:sticky [&_.line:before]:left-2 [&_.line:before]:z-10 [&_.line:before]:translate-y-[-1px] [&_.line:before]:pr-1 [&_pre]:h-[--height] [&_pre]:overflow-auto [&_pre]:!bg-transparent [&_pre]:pb-20 [&_pre]:pt-4 [&_pre]:font-mono [&_pre]:text-sm [&_pre]:leading-relaxed" v-html="activeCode" />
44+
<div :key="activeFile?.path" data-line-codeblock class="relative flex-1 overflow-hidden after:absolute after:inset-y-0 after:left-0 after:w-10 after:bg-zinc-950 [&_.line:before]:sticky [&_.line:before]:left-2 [&_.line:before]:z-10 [&_.line:before]:translate-y-[-1px] [&_.line:before]:pr-1 [&_pre]:h-[--height] [&_pre]:overflow-auto [&_pre]:!bg-transparent [&_pre]:pb-20 [&_pre]:pt-4 [&_pre]:font-mono [&_pre]:text-sm [&_pre]:leading-relaxed" v-html="activeFileMeta?.html" />
4245
</div>
4346
</div>
4447
</template>

0 commit comments

Comments
 (0)