1
0
Fork 1
mirror of https://github.com/elk-zone/elk.git synced 2024-11-14 12:59:59 +00:00
elk/components/content/ContentCode.vue

24 lines
556 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
2022-11-24 03:42:03 +00:00
}>()
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',
}
2022-11-25 21:09:10 +00:00
const highlighted = computed(() => {
return props.lang ? highlightCode(raw.value, (langMap[props.lang] || props.lang) as any) : raw
2022-11-24 03:42:03 +00:00
})
</script>
<template>
<pre v-if="lang" class="code-block" v-html="highlighted" />
<pre v-else class="code-block">{{ raw }}</pre>
2022-11-24 03:42:03 +00:00
</template>