1
0
mirror of https://github.com/elk-zone/elk synced 2024-11-27 22:38:11 +09:00
elk/components/content/ContentCode.vue
2022-11-26 04:19:48 +08:00

23 lines
489 B
Vue

<script setup lang="ts">
const props = defineProps<{
code: string
lang: string
}>()
const raw = $computed(() => decodeURIComponent(props.code).replace(/&#39;/g, '\''))
const langMap: Record<string, string> = {
js: 'javascript',
ts: 'typescript',
vue: 'html',
}
const hightlighted = computed(() => {
return props.lang ? highlightCode(raw, langMap[props.lang] || props.lang as any) : raw
})
</script>
<template>
<pre class="code-block" v-html="hightlighted" />
</template>