docs(ComponentCard): use inline highlighter (#664)

This commit is contained in:
Farnabaz
2023-09-12 15:49:44 +02:00
committed by GitHub
parent 0178ca9586
commit 1b34df15ac

View File

@@ -53,6 +53,8 @@
<script setup lang="ts"> <script setup lang="ts">
// @ts-expect-error // @ts-expect-error
import { transformContent } from '@nuxt/content/transformers' import { transformContent } from '@nuxt/content/transformers'
// @ts-ignore
import { useShikiHighlighter } from '@nuxtjs/mdc/runtime'
// eslint-disable-next-line vue/no-dupe-keys // eslint-disable-next-line vue/no-dupe-keys
const props = defineProps({ const props = defineProps({
@@ -205,12 +207,26 @@ function renderObject (obj: any) {
return obj return obj
} }
const shikiHighlighter = useShikiHighlighter({})
const codeHighlighter = async (code: string, lang: string, theme: any, highlights: any) => {
const styleMap = {}
const { tree, className } = await shikiHighlighter.getHighlightedAST(code, lang, theme, { styleMap, highlights })
return {
tree,
className,
style: shikiHighlighter.generateStyles(styleMap),
styleMap
}
}
const { data: ast } = await useAsyncData(`${name}-ast-${JSON.stringify({ props: componentProps, slots: props.slots })}`, () => transformContent('content:_markdown.md', code.value, { const { data: ast } = await useAsyncData(`${name}-ast-${JSON.stringify({ props: componentProps, slots: props.slots })}`, () => transformContent('content:_markdown.md', code.value, {
highlight: { markdown: {
theme: { highlight: {
light: 'material-theme-lighter', highlighter: codeHighlighter,
default: 'material-theme', theme: {
dark: 'material-theme-palenight' light: 'material-theme-lighter',
default: 'material-theme',
dark: 'material-theme-palenight'
}
} }
} }
}), { watch: [code] }) }), { watch: [code] })