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