Migrate mdc to comark

From comarkdown/comark · View interactive version

Migrate mdc to comark is an AI agent skill from the GitHub repository comarkdown/comark. Migrate a Nuxt project from @nuxtjs/mdc to Comark. Covers package changes, parse/render API mapping, AST format, Nuxt module config, components, slots, plugins, and Nuxt UI integration.

How to use this skill

Skill file

Migrate from @nuxtjs/mdc to Comark

@nuxtjs/mdc was Nuxt-only. Comark is its successor. The Markdown syntax is compatible, so your .md files need no changes. What changes is the JavaScript API.

The migration has two parts: the core package (programmatic API) and the Nuxt module (components, slots, and config).

Quick overview

Core package

API mapping

| @nuxtjs/mdc | comark |

|---|---|

| parseMarkdown(md, opts) | parseMarkdown(md, opts) from comark |

| createMarkdownParser(opts) (async) | createMarkdownParser(opts) (sync, no await) |

| stringifyMarkdown(body, data) | renderMarkdown(document) from comark/render |

| result.body (MDCRoot) | document.nodes (Node[]) |

| result.data | document.frontmatter |

| result.data.title | document.frontmatter.title |

| result.toc | document.meta.toc (requires toc plugin) |

| result.excerpt | document.meta.summary (requires summary plugin) |

AST format

| @nuxtjs/mdc | comark |

|---|---|

| { type: 'root', children: MDCNode[] } | { nodes: Node[], frontmatter: {}, meta: {} } |

| { type: 'element', tag: 'p', props: {}, children: [] } | ['p', {}, ...children] |

| { type: 'text', value: 'hello' } | 'hello' (plain string) |

Parse options

// Before: MDCOptions
{
  remark: { plugins: { /* record */ } },
  rehype: { options: {...}, plugins: { /* record */ } },
  highlight: { theme: '...', langs: [...] } | false,
  toc: { depth: 3, searchDepth: 2 } | false,
}

// After: ParserOptions
{
  plugins: ComarkPlugin[],   // ordered array, not a record
  autoUnwrap: true,          // removes <p> from single-paragraph containers
  autoClose: true,           // completes incomplete syntax (useful for streaming)
  // HTML, components, attributes, alerts, task-list, frontmatter are on by default
}

Plugins

The unified/remark/rehype pipeline is replaced by Comark's own lighter plugin interface.

| Feature | Before | After |

|---|---|---|

| Syntax highlighting | rehypeHighlight via createMarkdownParser | shiki() from comark/plugins/shiki |

| Table of contents | parseMarkdown(md, { toc: { depth: 3 } }) | toc({ depth: 3 }) plugin |

| Excerpt / summary | result.excerpt (built-in) | summary() plugin (document.meta.summary) |

| Emoji | remark-emoji (enabled by default) | emoji() plugin (opt-in) |

Available plugins include toc, shiki, emoji, task-list, summary, security, alert, math, mermaid, punctuation, and binding. Prefer framework paths in apps (@comark/vue/plugins/*), and use comark/plugins/* only with bare parseMarkdown().

Nuxt module

Configuration

// Before
export default defineNuxtConfig({
  modules: ['@nuxtjs/mdc'],
  mdc: { highlight: { ... }, remarkPlugins: { ... } },
})

// After
export default defineNuxtConfig({
  modules: ['@comark/vue'],
  // No plugin config here (plugins are defined per-component)
})

@comark/vue auto-imports Markdown, MarkdownDocument, defineMarkdownComponent, and defineMarkdownDocumentComponent.

Components

| @nuxtjs/mdc | @comark/vue |

|---|---|

| <MDCRenderer :body :data :components> | <MarkdownDocument :value :components> |

| <MDC :value :parser-options> | <Markdown :value :options> or <Markdown>{{ md }}</Markdown> |

| <MDCSlot /> | <slot /> |

| <MDCSlot unwrap="p" /> | <slot unwrap="p" /> |

| <slot mdc-unwrap="p" /> | <slot unwrap="p" /> |

For a pre-parsed document, use <MarkdownDocument> directly instead of <Markdown>.

`<MarkdownDocument>` props changes

| MDC <MDCRenderer> | Comark <MarkdownDocument> | Notes |

|---|---|---|

| body (MDCRoot) | value (MarkdownDocument) | Different AST shape |

| data | None | Frontmatter is in value.frontmatter |

| tag | None | Wrapper is always <div class="comark-content"> |

| prose | None | Prose* resolution is automatic |

| unwrap | unwrap prop / parse option | <Markdown unwrap /> or parse unwrap |

| None | data | Runtime values for data binding and {{ }}, not frontmatter |

| components | components | Same purpose |

| None | componentsManifest | New: dynamic async component resolver |

| None | streaming | New: streaming mode |

| None | effects | New: stream effects such as caret() and fade() from comark/effects |

Summary rendering
<!-- Before -->
<MDCRenderer :body="result.excerpt ?? result.body" :data="result.data" />

<!-- After -->
<Markdown summary>{{ markdown }}</Markdown>

`defineMarkdownComponent`

Replaces global mdc: { ... } config. Define reusable components with their own plugins and component mappings:

import { defineMarkdownComponent } from '@comark/vue'
import shiki from '@comark/vue/plugins/shiki'
import toc from '@comark/vue/plugins/toc'
import githubLight from '@shikijs/themes/github-light'
import githubDark from '@shikijs/themes/github-dark'

export const ArticleMarkdown = defineMarkdownComponent({
  name: 'ArticleMarkdown',
  plugins: [shiki({ themes: { light: githubLight, dark: githubDark } }), toc()],
  components: { alert: CustomAlert },
})

Slots

Replace <MDCSlot /> with native <slot />. Named slots work the same (#slotName in Markdown, <slot name="slotName"> in the component). The unwrap attribute (<slot unwrap="p">) strips wrapper tags from children.

Prose components

Prose*.vue uses the same naming convention, resolved internally as PascalCase (ProseP) rather than kebab-case (prose-p). The Comark Nuxt module does not register components/prose/ globally. Pass the components through components or defineMarkdownComponent(), or add components: [{ path: '~/components/prose', global: true, pathPrefix: false }, '~/components'] to nuxt.config.ts.

Nuxt UI integration

When using Nuxt UI, the @comark/vue Nuxt module registers Nuxt UI prose components automatically. Shorthand callout components are available:

::note    (informational)
::tip     (helpful suggestion)
::warning (something to watch out for)
::caution (critical warning)

These are only available with Nuxt UI. Without it, use ::callout{icon="..." color="..."}.

Common pitfalls

  1. createMarkdownParser is sync: no await needed (unlike @nuxtjs/mdc's createMarkdownParser).
  2. Code block language attribute: Comark sets attrs.language on <pre> nodes and class="language-*" on <code> nodes.
  3. Frontmatter: stored in document.frontmatter, not passed separately.
  4. renderMarkdown includes frontmatter: reads document.frontmatter automatically.
  5. No unified pipeline: mdc.config.ts hooks (pre, remark, rehype, post) have no direct equivalent; write a ComarkPlugin instead.
  6. Emoji is opt-in: not enabled by default like MDC's remark-emoji.

Component syntax

The MDC block and inline component syntax is identical, so no changes are needed in .md files for components, slots, and attributes.

Binding and data passing

Supported via the binding plugin + render-time data prop. Differences from MDC:

  1. Opt-in: register binding() and the framework Binding component.
  2. Namespaced paths: {{ data.user.name }}, {{ frontmatter.title }}, not bare {{ user.name }}.
  3. Data at render time: pass :data="{ user, count }" on <Markdown> / <MarkdownDocument>. Do not pass { data } into parseMarkdown.
<script setup lang="ts">
import binding, { Binding } from '@comark/vue/plugins/binding'
</script>

<template>
  <Markdown
    :value="markdown"
    :plugins="[binding()]"
    :components="{ Binding }"
    :data="{ user: { name: 'Ada' }, count: 3 }"
  />
</template>

:prefixed component props (:label="data.user.name") resolve without the binding plugin. Use the plugin for inline {{ path }} text (and renderer If for ::if).

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.