O Nitro UI oferece componentes de prose lindamente estilizados para o seu conteúdo markdown. Seja renderizando markdown com uma biblioteca ou usando os componentes de prose diretamente, o Nitro UI aplica seu design system para que o seu conteúdo se adapte automaticamente ao tema da sua aplicação.
@nuxtjs/mdc, @nuxt/content ou @comark/nuxt.prose no seu nuxt.config.ts:export default defineNuxtConfig({
modules: ['@nitro/ui'],
ui: {
prose: true
}
})
prose no seu vite.config.ts:import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import ui from '@nitro/ui/vite'
export default defineConfig({
plugins: [
vue(),
ui({
prose: true
})
]
})
Há várias maneiras de renderizar conteúdo estilizado:
Há várias maneiras de renderizar conteúdo estilizado:
Ao usar o @nuxt/content, renderize as páginas da sua coleção com o componente <ContentRenderer>:
<script setup lang="ts">
const route = useRoute()
const { data: page } = await useAsyncData(route.path, () => queryCollection('docs').path(route.path).first())
</script>
<template>
<ContentRenderer :value="page" />
</template>
Ao usar o @nuxtjs/mdc ou o @nuxt/content, use o componente <MDC> para renderizar strings markdown:
<script setup lang="ts">
const value = `# Hello World
Learn more about the **MDC** component in the [documentation](https://github.com/nuxt-content/mdc).
`
</script>
<template>
<MDC :value="value" />
</template>
@nuxtjs/mdc is being deprecated in favor of Comark. Your existing markdown files are compatible, no content changes needed.Comark renders markdown with built-in support for streaming. It incrementally renders tokens as they arrive, making it ideal for AI chat responses and any other dynamic markdown content.
<script setup lang="ts">
import highlight from '@comark/nuxt/plugins/highlight'
const markdown = ref('# Hello World\n\nThis is **streaming** markdown.')
</script>
<template>
<Comark :markdown="markdown" :plugins="[highlight()]" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { Comark } from '@comark/vue'
import highlight from '@comark/vue/plugins/highlight'
const markdown = ref('# Hello World\n\nThis is **streaming** markdown.')
</script>
<template>
<Comark :markdown="markdown" :plugins="[highlight()]" />
</template>
highlight adiciona realce de sintaxe aos blocos de código. Use a prop :streaming ao renderizar conteúdo que chega de forma incremental, como respostas de IA.Para dar suporte ao modo escuro, adicione o seguinte CSS à sua folha de estilo:html.dark .shiki span {
color: var(--shiki-dark) !important;
background-color: var(--shiki-dark-bg) !important;
font-style: var(--shiki-dark-font-style) !important;
font-weight: var(--shiki-dark-font-weight) !important;
text-decoration: var(--shiki-dark-text-decoration) !important;
}
Use o componente <ComarkRenderer> para renderizar um ComarkTree pré-processado sem enviar nenhum código de parser ou plugin ao navegador. Isso é útil quando o processamento acontece no servidor, em uma etapa de build ou via API.
<script setup lang="ts">
const { data: tree } = await useFetch('/api/content')
</script>
<template>
<ComarkRenderer v-if="tree" :tree="tree" />
</template>
<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { ComarkRenderer } from '@comark/vue'
const tree = ref()
onMounted(async () => {
tree.value = await fetch('/api/content').then(r => r.json())
})
</script>
<template>
<ComarkRenderer v-if="tree" :tree="tree" />
</template>
Use os componentes de prose diretamente nos templates Vue para máximo controle:
<template>
<ProseTable>
<ProseThead>
<ProseTr>
<ProseTh>Prop</ProseTh>
<ProseTh>Default</ProseTh>
</ProseTr>
</ProseThead>
<ProseTbody>
<ProseTr>
<ProseTd>
<ProseCode>color</ProseCode>
</ProseTd>
<ProseTd>
<ProseCode>neutral</ProseCode>
</ProseTd>
</ProseTr>
</ProseTbody>
</ProseTable>
</template>
Os elementos markdown são mapeados automaticamente para componentes de prose: # Heading vira <ProseH1>, **bold** vira <ProseStrong>, `code` vira <ProseCode>, e assim por diante.
MDC Syntax goes further by letting you use Vue components directly inside markdown. It is supported by Nuxt Content, Nuxt MDC and Comark.
Markdown comum com texto em negrito e itálico.
Use pnpm add @nitro/ui para instalar
Importe os componentes e use-os nos seus templates
pnpm add @nitro/ui
yarn add @nitro/ui
npm install @nitro/ui
bun add @nitro/ui
Regular markdown with **bold** and *italic* text.
::callout{icon="i-lucide-rocket" color="primary"}
Use MDC components for rich interactions!
::
::tabs
:::tabs-item{label="Installation"}
Use pnpm add @nitro/ui to install
:::
:::tabs-item{label="Usage"}
Import components and use them in your templates
:::
::
::code-group
```bash [pnpm]
pnpm add @nitro/ui
```
```bash [yarn]
yarn add @nitro/ui
```
```bash [npm]
npm install @nitro/ui
```
```bash [bun]
bun add @nitro/ui
```
::
Sobrescreva a estilização de qualquer componente de prose na configuração do seu app:
export default defineAppConfig({
ui: {
prose: {
h1: {
slots: {
base: 'scroll-m-20 text-4xl font-extrabold tracking-tight lg:text-5xl'
}
},
p: {
base: 'leading-7 [&:not(:first-child)]:mt-6'
}
}
}
})
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import ui from '@nitro/ui/vite'
export default defineConfig({
plugins: [
vue(),
ui({
ui: {
prose: {
h1: {
slots: {
base: 'scroll-m-20 text-4xl font-extrabold tracking-tight lg:text-5xl'
}
},
p: {
base: 'leading-7 [&:not(:first-child)]:mt-6'
}
}
}
})
]
})