---
title: "Migrating from MDX"
description: "Map every MDX concept (components, props, expressions, imports, and exports) to its Comark equivalent, with a step-by-step migration checklist."
canonical_url: "https://comark.dev/kb/migration-from-mdx"
---
# Migrating from MDX

> Map every MDX concept (components, props, expressions, imports, and exports) to its Comark equivalent, with a step-by-step migration checklist.

This guide maps MDX concepts to Comark. Both let you place components in Markdown, and Comark uses plain-text directives instead of JSX.

## Quick comparison

| Concept          | MDX                   | Comark                           |
| ---------------- | --------------------- | -------------------------------- |
| Block component  | `<Alert>...</Alert>`  | `::alert ... ::`                 |
| Inline component | `<Badge>text</Badge>` | `:badge[text]`                   |
| Props            | `<Alert type="info">` | `::alert{type="info"}`           |
| Self-closing     | `<Divider />`         | `::divider\n::`                  |
| Dynamic binding  | `year={year}`         | `:year="data.year"`              |
| Children         | JSX children          | Markdown between `::` delimiters |
| Imports          | `import X from './X'` | Component registered in renderer |
| Exports          | `export const x = 1`  | Frontmatter or application state |

## Components

### Block components

MDX uses JSX tags. Comark uses `::` fences:

::code-group
```js [MDX]
<Alert type="info">
  This is an important message with **bold** text.
</Alert>
```

```mdc [Comark]
::alert{type="info"}
This is an important message with **bold** text.
::
```
::

### Inline components

::code-group
```js [MDX]
Status: <Badge color="green">Active</Badge>
```

```mdc [Comark]
Status: :badge[Active]{color="green"}
```
::

### Self-closing components

::code-group
```js [MDX]
<Divider />
<Chart color="#fcb32c" />
```

```mdc [Comark]
::divider
::

::chart{color="#fcb32c"}
::
```
::

### Nested components

::code-group
```js [MDX]
<Card title="Example">
  <List>
    - Item 1
    - Item 2
  </List>
</Card>
```

```mdc [Comark]
::card{title="Example"}
  :::list
  - Item 1
  - Item 2
  :::
::
```
::

Nesting in Comark adds one colon per level, such as `::` for the outer block, `:::` for a child, and `::::` for deeper levels.

## Props and attributes

### Static props

::code-group
```js [MDX]
<Alert type="info" dismissible>
  Content
</Alert>
```

```mdc [Comark]
::alert{type="info" dismissible}
Content
::
```
::

### Dynamic and expression binding

MDX uses JSX curly-brace expressions. Comark uses `:prop="path"` [data binding](https://comark.dev/syntax/components#data-binding):

::code-group
```js [MDX]
<Chart year={currentYear} data={chartData} />
```

```mdc [Comark]
::chart{:year="data.currentYear" :data="data.chartData"}
::
```
::

A `:` prefix parses the attribute value as JSON at render time. When the value isn't valid JSON, the renderer resolves it as a path on `{ frontmatter, meta, data, props }`.

### Numeric and boolean props

::code-group
```js [MDX]
<Grid columns={3} fluid={true} />
```

```mdc [Comark]
::grid{:columns="3" fluid}
::
```
::

Boolean props without a value default to `true` in both formats.

## Imports and component registration

MDX imports components in each file. In Comark, you register components once in the renderer:

::code-group
```js [MDX]
import Alert from './components/Alert'
import Chart from './components/Chart'

# Dashboard

<Alert type="info">Welcome!</Alert>

<Chart data={metrics} />
```

~~~vue [Comark (Vue)]
<script setup>
import { Markdown } from '@comark/vue'
import Alert from './components/Alert.vue'
import Chart from './components/Chart.vue'

const markdown = `
# Dashboard

::alert{type="info"}
Welcome!
::

::chart{:data="data.metrics"}
::
`
</script>

<template>
  <Suspense>
    <Markdown :components="{ Alert, Chart }" :data="{ metrics }">{{ markdown }}</Markdown>
  </Suspense>
</template>
~~~

~~~tsx [Comark (React)]
import { Markdown } from '@comark/react'
import { Alert } from './components/Alert'
import { Chart } from './components/Chart'

const markdown = `
# Dashboard

::alert{type="info"}
Welcome!
::

::chart{:data="data.metrics"}
::
`

export default function Page() {
  return <Markdown components={{ Alert, Chart }} data={{ metrics }}>{markdown}</Markdown>
}
~~~
::

To share defaults across pages, create a configured component with `defineMarkdownComponent`:

```typescript
import { defineMarkdownComponent } from '@comark/vue' // or '@comark/react'
import Alert from './components/Alert'
import Chart from './components/Chart'

export const DocsMarkdown = defineMarkdownComponent({
  name: 'DocsMarkdown',
  components: { Alert, Chart },
})
```

## Exports and state

MDX uses `export` statements to define page-level variables:

```js
export const year = 2023

# Report for {year}
```

Comark doesn't run JavaScript inside Markdown. Use frontmatter (with the [binding plugin](https://comark.dev/plugins/built-in/binding)) for static metadata and application state for dynamic values:

::code-group
```mdc [Frontmatter]
---
year: 2023
---

# Report for {{ frontmatter.year }}
```

```vue [Application state (Vue)]
<script setup>
const year = ref(2023)
const markdown = computed(() => `# Report for ${year.value}`)
</script>

<template>
  <Suspense>
    <Markdown>{{ markdown }}</Markdown>
  </Suspense>
</template>
```
::

## Expressions in text

MDX evaluates JavaScript expressions in prose:

```js
The result is {2 + 3}.
Today is {new Date().toLocaleDateString()}.
```

Comark does not evaluate inline JavaScript expressions. Compute values in application code and interpolate them into the string before parsing, or pass them through the renderer's `data` prop with the [binding plugin](https://comark.dev/plugins/built-in/binding):

~~~typescript
const result = 2 + 3
const today = new Date().toLocaleDateString()

const markdown = `
The result is ${result}.
Today is ${today}.
`

const tree = await parseMarkdown(markdown)
~~~

## Layouts

MDX sets a layout component through a default export:

```js
export { default } from './layouts/BlogPost'

# My Post
```

In Comark, wrap the renderer in your layout component:

```vue
<template>
  <BlogPostLayout>
    <Suspense>
      <Markdown>{{ content }}</Markdown>
    </Suspense>
  </BlogPostLayout>
</template>
```

## Markdown features

Standard Markdown works the same way in both formats:

- Headings, paragraphs, and lists
- Bold, italic, and strikethrough
- Links and images
- Code blocks and inline code
- Blockquotes
- Tables
- Horizontal rules

## Migration checklist

1. Replace JSX tags with Comark `::component` and `:component` syntax.
2. Move per-file `import` statements to the renderer's `components` option.
3. Convert expression props from `prop={expr}` to `:prop="data.expr"` or JSON literals such as `:columns="3"`.
4. Replace inline expressions `{expr}` with string interpolation before parsing or `{{ data.path }}` via the [binding plugin](https://comark.dev/plugins/built-in/binding).
5. Move `export` values to YAML frontmatter or application state.
6. Remove layout exports and wrap `<Markdown>` in your layout component.
7. Install the official plugin packages you need ([`@comark/plugin-shiki`](https://comark.dev/plugins/official/shiki), [`@comark/plugin-katex`](https://comark.dev/plugins/official/katex), [`@comark/plugin-beautiful-mermaid`](https://comark.dev/plugins/official/beautiful-mermaid)) and register them in your parser or renderer setup.
8. Check that the default [`security()`](https://comark.dev/plugins/built-in/security) pass keeps what your content needs. MDX compiles content as trusted code, while Comark removes event handlers and `javascript:` URLs by default.

---

- [Component syntax](https://comark.dev/syntax/components)
- [Attributes](https://comark.dev/syntax/attributes)


## Sitemap

See the full [sitemap](https://comark.dev/sitemap.md) for all pages.
