Can i custom Nuxt MDC component style ?

i want Markdown style of vue press. but im not finding how to set it up and fix it. need description of config settings required for style change
2 Replies
kapa.ai
kapa.ai3w ago
Hi @코끼리. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Yes, you can customize the style of Nuxt MDC (Markdown Components) in your Nuxt project. While the knowledge sources don't provide specific information about replicating VuePress styles, they do offer guidance on how to customize the Markdown styling in Nuxt. Here's how you can approach this: 1. Use the .nuxt-content class: The <nuxt-content> component automatically adds a .nuxt-content class, which you can use to customize your styles. For example:
.nuxt-content h1 {
/* your custom h1 style */
}

.nuxt-content h1 {
/* your custom h1 style */
}

Nuxt Content V1 Styling (https://content.nuxt.com/v1/getting-started/displaying/#style) suggests this approach for basic customization. 2. Utilize Tailwind CSS Typography plugin: If you're using Tailwind CSS, you can use the Typography plugin to style your Markdown content. Here's how to set it up: a. Install the plugin:
npm install -D @tailwindcss/typography

npm install -D @tailwindcss/typography

b. Add the plugin to your tailwind.config.ts:
import tailwindTypography from '@tailwindcss/typography'

export default {
// ...other config
plugins: [tailwindTypography()]
}

import tailwindTypography from '@tailwindcss/typography'

export default {
// ...other config
plugins: [tailwindTypography()]
}

Stack Overflow Post (https://stackoverflow.com/questions/78565610) provides these steps for setting up the Typography plugin. 3. Configure Markdown options in nuxt.config.ts: You can customize various Markdown-related options in your Nuxt configuration file. For example:
export default defineNuxtConfig({
content: {
markdown: {
// Customize anchor links
anchorLinks: {
depth: 4,
exclude: [1]
},
// Enable or disable MDC syntax
mdc: true,
// Add remark plugins
remarkPlugins: {
'remark-emoji': {
emoticon: true
}
},
// Add rehype plugins
rehypePlugins: [
'rehype-figure'
]
}
}
})

export default defineNuxtConfig({
content: {
markdown: {
// Customize anchor links
anchorLinks: {
depth: 4,
exclude: [1]
},
// Enable or disable MDC syntax
mdc: true,
// Add remark plugins
remarkPlugins: {
'remark-emoji': {
emoticon: true
}
},
// Add rehype plugins
rehypePlugins: [
'rehype-figure'
]
}
}
})

These options allow you to control various aspects of Markdown rendering, as described in the Nuxt Content Configuration (https://content.nuxt.com/get-started/configuration/#markdown) documentation. 4. Custom components: You can override default Prose components by creating components with the same name in your project's components/content/ directory. For example, components/content/ProseA.vue would override the default link component. Nuxt Content Prose Components (https://content.nuxt.com/components/prose/) provides a list of available Prose components that you can customize. 5. Syntax highlighting: If you want to customize code block styling, you can configure a custom syntax highlighter. Nuxt Content supports various options, including Highlight.js and Shiki. Here's an example using Shiki:
import shiki from 'shiki'

export default {
modules: ['@nuxt/content'],
content: {
markdown: {
async highlighter() {
const highlighter = await shiki.getHighlighter({
theme: 'nord'
})
return (rawCode, lang) => {
return highlighter.codeToHtml(rawCode, lang)
}
}
}
}
}

import shiki from 'shiki'

export default {
modules: ['@nuxt/content'],
content: {
markdown: {
async highlighter() {
const highlighter = await shiki.getHighlighter({
theme: 'nord'
})
return (rawCode, lang) => {
return highlighter.codeToHtml(rawCode, lang)
}
}
}
}
}

This configuration is detailed in the Nuxt Content V1 Custom Highlighter (https://content.nuxt.com/v1/community/snippets/#custom-highlighter) documentation. While these options don't directly replicate VuePress styles, they provide you with the tools to customize your Markdown styling extensively. You may need to manually adjust your styles to match VuePress's appearance closely. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3w ago
<@485801576171175946> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Want results from more Discord servers?
Add your server