mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-27 02:10:40 +01:00
docs: use parseMarkdown instead of transformContent
This commit is contained in:
@@ -51,7 +51,6 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { transformContent } from '@nuxt/content/transformers'
|
|
||||||
import { upperFirst, camelCase, kebabCase } from 'scule'
|
import { upperFirst, camelCase, kebabCase } from 'scule'
|
||||||
import { useShikiHighlighter } from '~/composables/useShikiHighlighter'
|
import { useShikiHighlighter } from '~/composables/useShikiHighlighter'
|
||||||
|
|
||||||
@@ -270,27 +269,27 @@ function renderObject (obj: any) {
|
|||||||
return obj
|
return obj
|
||||||
}
|
}
|
||||||
|
|
||||||
const { data: ast } = await useAsyncData(
|
const { data: ast } = await useAsyncData(`${name}-ast-${JSON.stringify({ props: componentProps, slots: props.slots, code: props.code })}`, async () => {
|
||||||
`${name}-ast-${JSON.stringify({ props: componentProps, slots: props.slots, code: props.code })}`,
|
let formatted = ''
|
||||||
async () => {
|
try {
|
||||||
let formatted = ''
|
formatted = await $prettier.format(code.value, {
|
||||||
try {
|
trailingComma: 'none',
|
||||||
formatted = await $prettier.format(code.value) || code.value
|
semi: false,
|
||||||
} catch (error) {
|
singleQuote: true
|
||||||
formatted = code.value
|
|
||||||
}
|
|
||||||
|
|
||||||
return transformContent('content:_markdown.md', formatted, {
|
|
||||||
markdown: {
|
|
||||||
highlight: {
|
|
||||||
highlighter,
|
|
||||||
theme: {
|
|
||||||
light: 'material-theme-lighter',
|
|
||||||
default: 'material-theme',
|
|
||||||
dark: 'material-theme-palenight'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}, { watch: [code] })
|
} catch {
|
||||||
|
formatted = code.value
|
||||||
|
}
|
||||||
|
|
||||||
|
return parseMarkdown(formatted, {
|
||||||
|
highlight: {
|
||||||
|
highlighter,
|
||||||
|
theme: {
|
||||||
|
light: 'material-theme-lighter',
|
||||||
|
default: 'material-theme',
|
||||||
|
dark: 'material-theme-palenight'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}, { watch: [code] })
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="[&>div>pre]:!rounded-t-none [&>div>pre]:!mt-0">
|
<div class="[&>div>pre]:!rounded-t-none [&>div>pre]:!mt-0">
|
||||||
<div
|
<div v-if="hasPreview" class="flex border border-gray-200 dark:border-gray-700 relative rounded-t-md" :class="[{ 'p-4': padding, 'rounded-b-md': !hasCode, 'border-b-0': hasCode, 'not-prose': !prose }, backgroundClass, extraClass]">
|
||||||
v-if="hasPreview"
|
|
||||||
class="flex border border-gray-200 dark:border-gray-700 relative rounded-t-md"
|
|
||||||
:class="[{ 'p-4': padding, 'rounded-b-md': !hasCode, 'border-b-0': hasCode, 'not-prose': !prose }, backgroundClass, extraClass]"
|
|
||||||
>
|
|
||||||
<template v-if="component">
|
<template v-if="component">
|
||||||
<iframe v-if="iframe" :src="`/examples/${component}`" v-bind="iframeProps" :class="backgroundClass" class="w-full" />
|
<iframe v-if="iframe" :src="`/examples/${component}`" v-bind="iframeProps" :class="backgroundClass" class="w-full" />
|
||||||
<component :is="camelName" v-else v-bind="componentProps" :class="componentClass" />
|
<component :is="camelName" v-else v-bind="componentProps" :class="componentClass" />
|
||||||
@@ -22,7 +18,6 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { camelCase } from 'scule'
|
import { camelCase } from 'scule'
|
||||||
import { fetchContentExampleCode } from '~/composables/useContentExamplesCode'
|
import { fetchContentExampleCode } from '~/composables/useContentExamplesCode'
|
||||||
import { transformContent } from '@nuxt/content/transformers'
|
|
||||||
import { useShikiHighlighter } from '~/composables/useShikiHighlighter'
|
import { useShikiHighlighter } from '~/composables/useShikiHighlighter'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
@@ -86,15 +81,13 @@ const highlighter = useShikiHighlighter()
|
|||||||
const hasCode = computed(() => !props.hiddenCode && (data?.code || instance.slots.code))
|
const hasCode = computed(() => !props.hiddenCode && (data?.code || instance.slots.code))
|
||||||
const hasPreview = computed(() => !props.hiddenPreview && (props.component || instance.slots.default))
|
const hasPreview = computed(() => !props.hiddenPreview && (props.component || instance.slots.default))
|
||||||
|
|
||||||
const { data: ast } = await useAsyncData(`content-example-${camelName}-ast`, () => transformContent('content:_markdown.md', `\`\`\`vue\n${data?.code ?? ''}\n\`\`\``, {
|
const { data: ast } = await useAsyncData(`content-example-${camelName}-ast`, () => parseMarkdown(`\`\`\`vue\n${data?.code ?? ''}\n\`\`\``, {
|
||||||
markdown: {
|
highlight: {
|
||||||
highlight: {
|
highlighter,
|
||||||
highlighter,
|
theme: {
|
||||||
theme: {
|
light: 'material-theme-lighter',
|
||||||
light: 'material-theme-lighter',
|
default: 'material-theme',
|
||||||
default: 'material-theme',
|
dark: 'material-theme-palenight'
|
||||||
dark: 'material-theme-palenight'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
|
|||||||
@@ -3,11 +3,10 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { transformContent } from '@nuxt/content/transformers'
|
|
||||||
import { upperFirst, camelCase } from 'scule'
|
import { upperFirst, camelCase } from 'scule'
|
||||||
import json5 from 'json5'
|
import json5 from 'json5'
|
||||||
import { useShikiHighlighter } from '~/composables/useShikiHighlighter'
|
|
||||||
import * as config from '#ui/ui.config'
|
import * as config from '#ui/ui.config'
|
||||||
|
import { useShikiHighlighter } from '~/composables/useShikiHighlighter'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
slug: {
|
slug: {
|
||||||
@@ -18,6 +17,7 @@ const props = defineProps({
|
|||||||
|
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const highlighter = useShikiHighlighter()
|
const highlighter = useShikiHighlighter()
|
||||||
|
|
||||||
// eslint-disable-next-line vue/no-dupe-keys
|
// eslint-disable-next-line vue/no-dupe-keys
|
||||||
const slug = props.slug || route.params.slug[route.params.slug.length - 1]
|
const slug = props.slug || route.params.slug[route.params.slug.length - 1]
|
||||||
const camelName = camelCase(slug)
|
const camelName = camelCase(slug)
|
||||||
@@ -25,19 +25,17 @@ const name = `U${upperFirst(camelName)}`
|
|||||||
|
|
||||||
const preset = config[camelName]
|
const preset = config[camelName]
|
||||||
|
|
||||||
const { data: ast } = await useAsyncData(`${name}-preset`, () => transformContent('content:_markdown.md', `
|
const { data: ast } = await useAsyncData(`${name}-preset`, () => parseMarkdown(`
|
||||||
\`\`\`yml
|
\`\`\`yml
|
||||||
${json5.stringify(preset, null, 2)}
|
${json5.stringify(preset, null, 2).replace(/,([ |\t\n]+[}|\])])/g, '$1')}
|
||||||
\`\`\`\
|
\`\`\`\
|
||||||
`, {
|
`, {
|
||||||
markdown: {
|
highlight: {
|
||||||
highlight: {
|
highlighter,
|
||||||
highlighter,
|
theme: {
|
||||||
theme: {
|
light: 'material-theme-lighter',
|
||||||
light: 'material-theme-lighter',
|
default: 'material-theme',
|
||||||
default: 'material-theme',
|
dark: 'material-theme-palenight'
|
||||||
dark: 'material-theme-palenight'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
|
|||||||
Reference in New Issue
Block a user