To achieve a component preview in your Nuxt Content docs—where you can both display the component and its source code with proper highlighting—there are built-in solutions in the Nuxt ecosystem that are much simpler than the full Nuxt UI docs setup.
Use MDC Syntax with Nuxt Content
Nuxt Content supports MDC syntax, which allows you to embed Vue components directly in your Markdown files. You can place your component in the /components/content directory and then use it in your Markdown like this:
::my-component
#default
This is the default slot content.
::
This will render the component live in your docs. However, this does not automatically show the source code.
Displaying Code and Preview Side-by-Side
For a simple and effective solution, you can use the code-preview component from Nuxt UI Pro, which is designed for exactly this use case. It lets you wrap a code block and display both the rendered component and its code with syntax highlighting:
::code-preview
#default
<MyComponent prop="value" />
code
```vue
<MyComponent prop="value" />
::
- The `#default` slot renders the live component.
- The `code` slot displays the code with highlighting.
This approach is used in Nuxt UI Pro docs and is much simpler than building a custom solution from scratch. You can customize the appearance via your `app.config.ts` if needed. Code highlighting is handled by Shiki, and you can configure themes in your `nuxt.config.ts` under `content.build.markdown.highlight`[Nuxt UI Typography](<https://ui.nuxt.com/getting-started/typography#codepreview>), [Nuxt Content Markdown Highlight](<https://content.nuxt.com/docs/getting-started/configuration#highlight>).
### Requirements