2022-11-24 12:42:03 +09:00
|
|
|
<script setup lang="ts">
|
|
|
|
const props = defineProps<{
|
|
|
|
code: string
|
2022-12-02 11:19:31 +09:00
|
|
|
lang?: string
|
2022-11-24 12:42:03 +09:00
|
|
|
}>()
|
|
|
|
|
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',
|
|
|
|
}
|
|
|
|
|
2022-11-26 06:09:10 +09:00
|
|
|
const highlighted = computed(() => {
|
2022-12-02 11:19:31 +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>
|
2023-01-15 19:48:22 +09:00
|
|
|
<pre v-if="lang" class="code-block" v-html="highlighted" />
|
|
|
|
<pre v-else class="code-block">{{ raw }}</pre>
|
2022-11-24 12:42:03 +09:00
|
|
|
</template>
|