Integrating Comark with Nuxt UI
comarknuxtintegration
This example uses Nuxt 4 with Comark as the Markdown parser and renderer, and Nuxt UI for prose styling.
How it works
Instead of chaining gray-matter, remark, and rehype, a Nitro server route parses Markdown and frontmatter in one step:
- Read Markdown files: load
.mdfiles fromcontent/posts/inside a server route. - Parse with Comark: call
parseMarkdown()withshiki()to build theMarkdownDocumentand readtree.frontmatter. - Generate static pages: run
nuxt generateto pre-render all post routes. - Render in Vue: pass
post.treeto the auto-imported<MarkdownDocument>component.
// server/api/posts/[slug].get.ts
import { parseMarkdown } from 'comark'
import shiki from 'comark/plugins/shiki'
const tree = await parseMarkdown(content, {
plugins: [shiki()],
})
return { slug, title, description, pubDate, tags, tree }<!-- app/pages/blog/[slug].vue -->
<script setup lang="ts">
const route = useRoute()
const { data: post } = await useFetch(`/api/posts/${route.params.slug}`)
</script>
<template>
<MarkdownDocument :value="post.tree" />
</template>@comark/vue Nuxt module detects @nuxt/ui and turns on its prose component set without extra configuration.Nuxt UI prose components
When both @comark/vue and @nuxt/ui are installed, the module sets ui.prose = true, registering Nuxt UI's Prose* components globally:
ProseH1,ProseH2, andProseH3for headingsProsePfor paragraphsProseCodeandProsePrefor inline and fenced codeProseUl,ProseOl, andProseLifor listsProseA,ProseBlockquote, andProseTablefor links, quotes, and tables
MarkdownDocument resolves standard Markdown tags to these global components automatically.
Custom components
Custom components in app/components/ receive props and default slot content from the Comark document:
<!-- app/components/Alert.vue -->
<script setup lang="ts">
defineProps<{ type?: 'info' | 'warning' | 'success' | 'danger' }>()
</script>
<template>
<UAlert :color="color" variant="soft" class="my-4">
<template #description><slot /></template>
</UAlert>
</template>Because Nuxt registers components in app/components/, MarkdownDocument resolves ::alert to Alert.vue.