-
Notifications
You must be signed in to change notification settings - Fork 57
Description
Frank
Hola everyone,
I really struggled to render an MDC Component with simple text inside our component as well.
The Problem
I expected when I write:
```ts [nuxt.config.ts]
export default defineNuxtConfig({
modules: ['@nuxt/ui-pro']
})
```
I expected to render the component, but it didn't work. It never retrieved syntax highlighting.
Research Done
I made some research, but they didn't help either:
What I Want
The reason is that I want to have a nice showcase component without creating an extra markdown file in my content folder—a nice self-contained component that uses the MDC component.
Because I want to keep everything super lean, I didn't want to mess around too much with my codebase. After a while, I think that's actually an issue and it's not on my side, or maybe I am wrong, who knows.
Anyway, that's why I am firing up this issue here.
Thanks for reading :)
Best regards,
Frank
CLAUDE: Bug Report for Nuxt UI Pro GitHub Issue
Title
ProsePre/ProseCode components lack syntax highlighting when used directly in Vue templates + MDC endpoint issues with Nuxt 4
Environment
- Nuxt: 4.0.3
- @nuxt/ui-pro: 3.3.0
- @nuxt/content: 3.6.3
- @nuxtjs/mdc: 0.9.5
- Node: v20+
Reproduction
Repository/StackBlitz link: [Provide minimal reproduction]
Description
When using Prose components (ProsePre
, ProseCode
) directly in Vue templates for displaying code blocks, syntax highlighting doesn't work despite proper configuration. Additionally, using MDC component with language specifiers causes 404 errors for non-existent /api/_mdc/highlight
endpoint.
Current Behavior
Issue 1: No Syntax Highlighting with Direct Prose Component Usage
<template>
<ProsePre language="typescript" :code="codeExample">
<code>{{ codeExample }}</code>
</ProsePre>
</template>
<script setup>
const codeExample = `// TypeScript code here`
</script>
Result: Renders as plain monospace text without syntax highlighting colors
Issue 2: MDC Component Endpoint Errors
<template>
<MDC :value="markdownContent" tag="div" />
</template>
<script setup>
const markdownContent = `
\`\`\`typescript [filename.ts]
// Code here
\`\`\`
`
</script>
Result: Console errors:
WARN [Vue Router warn]: No match found for location with path "/api/_mdc/highlight?code=..."
Expected Behavior
- ProsePre/ProseCode should apply Shiki syntax highlighting when used directly in templates
- MDC component should handle dynamic markdown strings with language specifiers without attempting to fetch non-existent endpoints
Root Cause Analysis
Based on investigation:
-
Prose Components Issue: When used directly in templates, Prose components bypass the MDC/Nuxt Content preprocessing pipeline where Shiki syntax highlighting is applied. They only receive raw text and apply styling (monospace font, background) but not token-level syntax coloring.
-
MDC Endpoint Issue: The
/api/_mdc/highlight
endpoint doesn't exist in Nuxt Content v3 (uses build-time processing). This appears to be a compatibility issue between Nuxt 4.0.3 and current MDC/Content modules when processing dynamic markdown strings.
Workaround
Currently working around by using MDC without language specifiers:
const markdownContent = `
\`\`\`
// Code without language specifier
\`\`\`
`
Suggested Solutions
-
For Prose Components:
- Add runtime Shiki processing capability for direct template usage
- Or document that these components require preprocessed content
- Consider exposing a
useShikiHighlight
composable for manual highlighting
-
For MDC Component:
- Fix compatibility with Nuxt 4 for dynamic markdown processing
- Implement proper runtime highlighting without endpoint dependency
- Or provide clear configuration to enable runtime highlighting
Additional Context
This impacts developers trying to display syntax-highlighted code blocks on landing pages or documentation without using file-based content. The issue is particularly problematic for dynamic content from APIs or user input.
The research shows this is a fundamental architectural limitation where:
- Nuxt Content v3 processes syntax highlighting at build time for file-based content
- Dynamic string content doesn't go through this preprocessing pipeline
- The MDC component attempts to use a runtime API that doesn't exist in v3
Steps to Reproduce
- Create a fresh Nuxt 4 project with UI Pro
- Add @nuxt/content and @nuxtjs/mdc modules
- Try to use ProsePre with language prop in a component
- Observe no syntax highlighting
- Switch to MDC with language specifiers
- Observe console errors about missing endpoint
Configuration Used
// nuxt.config.ts
export default defineNuxtConfig({
modules: ["@nuxt/eslint", "@nuxt/ui-pro", "@nuxt/content", "@nuxtjs/mdc", "@nuxt/icon"],
uiPro: {
mdc: true
},
content: {
build: {
markdown: {
highlight: {
theme: {
default: 'github-light',
dark: 'github-dark'
},
langs: ['ts', 'js', 'json', 'bash', 'vue', 'html', 'css', 'md', 'yaml']
}
}
}
},
mdc: {
highlight: {
theme: {
default: 'github-light',
dark: 'github-dark'
},
langs: ['typescript', 'javascript', 'json', 'bash', 'vue', 'html', 'css', 'markdown', 'yaml'],
wrapperStyle: true
},
components: {
prose: true
}
}
})
Impact: Medium-High - Affects all developers trying to use syntax highlighting for dynamic code content
Workaround Available: Yes, but limited (no language-specific highlighting)
Checklist
- I have searched existing issues
- I have provided a minimal reproduction
- I have included all relevant error messages
- I have tested with latest versions