feat: support codeblock
This commit is contained in:
parent
4885b165df
commit
0a8841f4f4
13 changed files with 201 additions and 52 deletions
|
@ -18,7 +18,7 @@ export default defineComponent({
|
|||
return () => h(
|
||||
'div',
|
||||
{ class: 'rich-content' },
|
||||
contentToVNode(props.content, undefined, emojiObject),
|
||||
contentToVNode(props.content, emojiObject),
|
||||
)
|
||||
},
|
||||
})
|
||||
|
|
22
components/content/ContentCode.vue
Normal file
22
components/content/ContentCode.vue
Normal file
|
@ -0,0 +1,22 @@
|
|||
<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 hightlighted = computed(() => {
|
||||
return highlightCode(raw.value, langMap[props.lang] || props.lang as any)
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<pre class="code-block" v-html="hightlighted" />
|
||||
</template>
|
Loading…
Add table
Add a link
Reference in a new issue