1
0
mirror of https://github.com/elk-zone/elk synced 2024-12-01 00:08:11 +09:00
elk/components/content/ContentCode.vue

23 lines
487 B
Vue
Raw Normal View History

2022-11-24 12:42:03 +09:00
<script setup lang="ts">
const props = defineProps<{
code: string
lang: string
}>()
const raw = $computed(() => decodeURIComponent(props.code).replace(/&#39;/g, '\''))
2022-11-24 12:42:03 +09:00
const langMap: Record<string, string> = {
js: 'javascript',
ts: 'typescript',
vue: 'html',
}
2022-11-26 06:09:10 +09:00
const highlighted = computed(() => {
return props.lang ? highlightCode(raw, langMap[props.lang] || props.lang as any) : raw
2022-11-24 12:42:03 +09:00
})
</script>
<template>
2022-11-26 06:09:10 +09:00
<pre class="code-block" v-html="highlighted" />
2022-11-24 12:42:03 +09:00
</template>