elk/components/content/ContentCode.vue

23 lines
489 B
Vue
Raw Normal View History

2022-11-24 03:42:03 +00:00
<script setup lang="ts">
const props = defineProps<{
code: string
lang: string
}>()
const raw = $computed(() => decodeURIComponent(props.code).replace(/&#39;/g, '\''))
2022-11-24 03:42:03 +00:00
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
2022-11-24 03:42:03 +00:00
})
</script>
<template>
<pre class="code-block" v-html="hightlighted" />
</template>