docs: highlight inline type code in props table

This commit is contained in:
Anthony Fu
2024-06-27 16:28:11 +02:00
parent b5f42cdd3a
commit 1d61d8d152
4 changed files with 28 additions and 12 deletions

View File

@@ -32,9 +32,7 @@ const meta: ComputedRef<ComponentMeta> = computed(() => componentMeta.value.meta
</ProseCodeInline>
</ProseTd>
<ProseTd>
<ProseCodeInline v-if="event.type" lang="ts">
{{ event.type }}
</ProseCodeInline>
<HighlightInlineType v-if="event.type" :type="event.type" />
</ProseTd>
</ProseTr>
</ProseTbody>

View File

@@ -50,14 +50,10 @@ console.log('meta.value', meta.value)
</ProseCodeInline>
</ProseTd>
<ProseTd>
<ProseCodeInline v-if="prop.default">
{{ prop.default }}
</ProseCodeInline>
<HighlightInlineType v-if="prop.default" :type="prop.default" />
</ProseTd>
<ProseTd>
<ProseCodeInline v-if="prop.type" lang="ts">
{{ prop.type }}
</ProseCodeInline>
<HighlightInlineType v-if="prop.type" :type="prop.type" />
<ProseP class="mt-1 mb-0 text-gray-500 dark:text-gray-400">
{{ prop.description }}

View File

@@ -32,9 +32,7 @@ const meta: ComputedRef<ComponentMeta> = computed(() => componentMeta.value.meta
</ProseCodeInline>
</ProseTd>
<ProseTd>
<ProseCodeInline v-if="slot.type" lang="ts">
{{ slot.type }}
</ProseCodeInline>
<HighlightInlineType v-if="slot.type" :type="slot.type" />
<ProseP class="mt-1 mb-0 text-gray-500 dark:text-gray-400">
{{ slot.description }}

View File

@@ -0,0 +1,24 @@
<script setup lang="ts">
import { parseMarkdown } from '@nuxtjs/mdc/runtime'
const props = defineProps<{
type: string
}>()
const { data: ast } = await useAsyncData<any>(`hightlight-inline-code-` + props.type, async () => {
const ast = await parseMarkdown(`\`type _ = ${props.type}\`{lang="ts"}`)
const p = ast.body.children[0]
const code = p.children[0]
// Remove the `type _ = ` part
code.children = code.children.slice(3)
ast.body.children = [code]
return ast
})
</script>
<template>
<MDCRenderer v-if="ast" :body="ast.body" :data="ast.data" />
</template>