mirror of
https://github.com/elk-zone/elk.git
synced 2024-12-28 15:38:18 +03:00
23 lines
556 B
Vue
23 lines
556 B
Vue
<script setup lang="ts">
|
|
const props = defineProps<{
|
|
code: string
|
|
lang?: string
|
|
}>()
|
|
|
|
const raw = computed(() => decodeURIComponent(props.code).replace(/'/g, '\''))
|
|
|
|
const langMap: Record<string, string> = {
|
|
js: 'javascript',
|
|
ts: 'typescript',
|
|
vue: 'html',
|
|
}
|
|
|
|
const highlighted = computed(() => {
|
|
return props.lang ? highlightCode(raw.value, (langMap[props.lang] || props.lang) as any) : raw
|
|
})
|
|
</script>
|
|
|
|
<template>
|
|
<pre v-if="lang" class="code-block" v-html="highlighted" />
|
|
<pre v-else class="code-block">{{ raw }}</pre>
|
|
</template>
|