mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-28 19:00:35 +01:00
docs(ComponentCard): use inline highlighter (#664)
This commit is contained in:
@@ -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] })
|
||||||
|
|||||||
Reference in New Issue
Block a user