Rendering Markdown Content in Nuxt 4
Markdown is the natural format for blog content. Here's how to render it beautifully in a Nuxt 4 application.
Parsing Markdown
Use a lightweight markdown parser like markdown-it:
``ts
import MarkdownIt from 'markdown-it'
const md = new MarkdownIt({
html: true,
linkify: true,
typographer: true,
highlight(str: string, lang: string) {
// Add syntax highlighting here
return <pre><code class="language-x">...code...</code></pre>
}
})
const html = md.render('# Hello World')
`
Creating a Composable
Wrap it in a Vue composable for easy use:
`ts
export function useMarkdown(content: string) {
const html = computed(() => md.render(content))
return { html }
}
`
Frontmatter Extraction
Parse YAML frontmatter for metadata:
`md
title: My Post
date: 2025-08-15
tags: [nuxt, markdown]
Content starts here
`Styling Markdown Output
Brutalist markdown styling:
`css
.markdown-body h1 {
font-family: 'JetBrains Mono', monospace;
text-transform: uppercase;
border-bottom: 3px solid #00ff41;
padding-bottom: 0.5rem;
}.markdown-body code {
font-family: 'JetBrains Mono', monospace;
background: #1a1a1a;
color: #00ff41;
padding: 0.15em 0.4em;
}
.markdown-body pre {
background: #0a0a0a;
border: 2px solid #333;
padding: 1.5rem;
overflow-x: auto;
}
.markdown-body blockquote {
border-left: 4px solid #00ff41;
padding-left: 1rem;
color: #888;
font-style: italic;
}
`Full Integration
The complete flow:
- Store blog posts with markdown body in
blogPosts.ts.
Import and parse in page components.
Render with v-html` in the template.
More in Development
Migrating from Nuxt 3 to Nuxt 4: A Practical Guide
Step-by-step walkthrough of the Nuxt 4 migration process, covering the new directory structure, composables, and performance improvements.
Adding Blazing-Fast Client-Side Search with Fuse.js
Implement fuzzy search for your blog using Fuse.js — zero server requirements, instant results, and a great developer experience.