feat: support codeblock

This commit is contained in:
Anthony Fu 2022-11-24 11:42:03 +08:00
parent 4885b165df
commit 0a8841f4f4
13 changed files with 201 additions and 52 deletions

View file

@ -18,7 +18,7 @@ export default defineComponent({
return () => h(
'div',
{ class: 'rich-content' },
contentToVNode(props.content, undefined, emojiObject),
contentToVNode(props.content, emojiObject),
)
},
})

View file

@ -0,0 +1,22 @@
<script setup lang="ts">
const props = defineProps<{
code: string
lang: string
}>()
const raw = computed(() => decodeURIComponent(props.code).replace(/&#39;/g, '\''))
const langMap: Record<string, string> = {
js: 'javascript',
ts: 'typescript',
vue: 'html',
}
const hightlighted = computed(() => {
return highlightCode(raw.value, langMap[props.lang] || props.lang as any)
})
</script>
<template>
<pre class="code-block" v-html="hightlighted" />
</template>