Comark Kitchen Sink

A comprehensive demo of every Comark feature: components in Markdown for React. Each section shows the MDC source alongside its rendered output.

Basic Markdown

Comark supports full GitHub Flavored Markdown: headings, bold, italic, strikethrough, inline code, blockquotes, lists, tables, links, and horizontal rules.

Block Components

Block components use ::component-name{props} syntax and occupy their own line. They receive children as React children and props from the {key="value"} syntax.

Inline Components

Inline components use :component-name[content]{props} syntax and flow within paragraph text. Content in brackets becomes the component's children.

Component Props

Components accept props via {key="value"} for strings, {bool} for booleans, {#id} for IDs, and {.class} for CSS classes. All are passed to your React component.

YAML Frontmatter Props

For components with many or complex properties (arrays, objects, nested config), use YAML frontmatter between --- delimiters right after the opening :: tag.

Named Slots

Block components support named slots with #slot-name syntax. In React, the default slot maps to children and named slots become slotPascalName props.

Nested Components

Components can be nested inside each other by adding extra colons for each nesting level. The parser matches opening and closing tags automatically.

Element Attributes

Add custom classes, IDs, styles, and data attributes to native Markdown elements like bold, italic, links, and images using {.class #id key="value"} after the element.

Plugins

Comark ships with built-in plugins that extend markdown with emoji, syntax highlighting, math, alerts, task lists, and more. Pass them via the plugins prop.

import emoji      from "comark/plugins/emoji"
import footnotes  from "comark/plugins/footnotes"
import math       from "comark/plugins/math"
import highlight  from "comark/plugins/highlight"
import mermaid    from "comark/plugins/mermaid"
import jsonRender from "comark/plugins/json-render"
import security   from "comark/plugins/security"

// Alerts (> [!NOTE]) are built-in — no import needed!

<ComarkClient plugins={[emoji(), math(), footnotes(), highlight(), mermaid(), jsonRender()]}>
  {content}
</ComarkClient>

Alerts (built-in)

GitHub-style alert blockquotes are built into Comark -- no plugin import needed. Uses > [!TYPE] syntax for NOTE, TIP, IMPORTANT, WARNING, and CAUTION. Register a custom blockquote component to add icons and colors.

Emoji Plugin

Converts emoji shortcodes like :smile: and :rocket: into real Unicode emoji characters. Import from comark/plugins/emoji. No configuration needed.

Emoji shortcodes are converted to real emoji characters:

I ❤️ Comark! It's 🚀 fast and ✨ beautiful.

👋 Hello! How are you 😄 today?

Combine with markdown: 🔥 Hot take — Comark is 💯 percent awesome 🎉

Some more: 👍 👎 👀 ⚠️ 💡 📝

Task List Plugin

Renders interactive checkboxes from standard [ ] and [x] list syntax. Supports nesting. Import from comark/plugins/task-list.

Footnotes Plugin

Adds footnote references [^label] and definitions [^label]: content. References become superscript links; definitions collect into a numbered list at the end. Import from comark/plugins/footnotes.

Math Plugin (KaTeX)

Renders LaTeX math with KaTeX. Inline: $E = mc^2$. Display: $$...$$. Requires katex peer dep. Register the Math component for rendering. Import from comark/plugins/math.

Inline math uses single dollar signs: is Einstein's famous equation.

The quadratic formula is .

Display math uses double dollar signs for block equations:

Mix with markdown: the Pythagorean theorem states that .

Syntax Highlighting (Shiki)

Shiki-powered syntax highlighting with dual-theme support. Languages are loaded on demand. Requires shiki peer dep. Import from comark/plugins/highlight.

Mermaid Diagrams

Renders Mermaid diagrams from ```mermaid code blocks. Requires beautiful-mermaid peer dep. Register the Mermaid component for rendering. Import from comark/plugins/mermaid.

Mermaid diagrams render from ```mermaid code blocks:

JSON Render Plugin

Transforms ```json-render and ```yaml-render code blocks into live UI. The type field in the spec maps to registered component names. Supports both full specs (root + elements tree) and single-element shorthand. Import from comark/plugins/json-render.

Security Sanitization

Sanitizes the parsed AST by removing dangerous elements (script, iframe), blocking malicious protocols (javascript:, vbscript:), and stripping event handlers (onclick, onerror). Import from comark/plugins/security.

TOC Plugin

Generates a hierarchical table of contents from headings and stores it in tree.meta.toc. Heading IDs are auto-generated for anchor linking. Import from comark/plugins/toc.

Excerpt / Summary Plugin

Splits content at the <!--more--> delimiter to extract excerpts for blog post previews or meta descriptions. The excerpt is exposed via tree.meta.summary. Import from comark/plugins/summary.

Styling Guide

Three layers control how Comark output looks: global CSS rules, inline element attributes, and custom component styling.

How the 3 layers work together

Layer 1
.comark-output CSS

Global rules in globals.css style native markdown elements: headings, lists, tables, code, blockquotes.

Layer 2
Element Attributes {.class}

Inline {.class #id} syntax adds Tailwind classes directly to markdown elements in your MDC content.

Layer 3
Component Styling

Custom React components own their visual design. MDC passes data via props; the component renders with Tailwind, CSS modules, or any approach.

Layer 1: Global CSS Rules

The .comark-output class in globals.css provides base styles for all native markdown elements. These rules use Tailwind's @apply for consistent theming. Override or extend them to change the look of all rendered markdown.

Layer 2: Inline Element Attributes

Use {.tailwind-class} after any markdown element to add Tailwind classes inline. This is Comark's attribute syntax -- it works on bold, italic, links, spans, and more. Multiple classes are space-separated.

Layer 3: Component Styling

Custom MDC components are regular React components styled however you like. Props from MDC (type, title, etc.) drive variant logic inside the component. The MDC author writes semantic markup; the component author controls the visual output.

Streaming Mode

Comark can render content as it arrives, token by token. The streaming prop tells the renderer content is still arriving, and caret adds a blinking cursor. The parser auto-closes incomplete markdown so partial bold, lists, and components render correctly mid-stream.

Press "Start Stream" to simulate an LLM streaming response...

Live Playground

Edit the MDC source on the left and see the rendered output update in real time. All registered components (alert, card, badge, callout, steps, step, tabs, divider) are available.

Editor
Preview

LLM System Prompt

Copy this system prompt and give it to any LLM (GPT, Claude, Gemini, etc.) so it knows how to write content using your registered Comark components. It covers MDC syntax, all available components, built-in features, and best practices.

system-prompt.md200 lines
You are a content writer that outputs structured Markdown using **Comark MDC syntax** — an extension of standard Markdown that adds component directives.

## Rules

1. Write valid CommonMark Markdown for all standard formatting (headings, bold, italic, links, lists, code blocks, blockquotes, tables).
2. Use MDC component syntax to embed rich UI components. Components are case-sensitive and must match the registered names exactly.
3. Never invent component names that are not listed below.
4. Every block component must be closed with `::` (or matching colons for nested levels).

---

## MDC Syntax Reference

### Block Components

Open with `::`, close with `::`. Props go in curly braces. Content between the delimiters becomes `children`.

```
::component-name{prop="value" anotherProp="value"}
Markdown content here (rendered as children)
::
```

### Inline Components

Single colon, square brackets for visible text, curly braces for props:

```
:component-name[visible text]{prop="value"}
```

### YAML Frontmatter Props

For complex props (arrays, objects), use a YAML block between `---` fences inside the component:

```
::component-name
---
title: My Title
items:
  - one
  - two
---
Body content
::
```

### Named Slots

Use `#slotName` inside a block component to assign content to a named slot:

```
::card{title="Example"}
#header
This goes into the slotHeader prop

Default content goes into children

#footer
This goes into the slotFooter prop
::
```

### Nesting Components

Add extra colons for each nesting level:

```
::outer
:::inner
Content
:::
::
```

### Element Attributes

Add attributes to inline markdown elements:

```
**bold text**{.my-class}
[styled span]{.bg-accent .px-2}
```

---

## Available Components

### `alert` (block)
Colored alert box with icon. Types: info, warning, error, success.
```
::alert{type="info"}
This is an informational message.
::
```

### `card` (block)
Card with optional title and named slots for header/footer.
```
::card{title="Card Title"}
#header
Optional header content

Main body content

#footer
Optional footer content
::
```

### `badge` (inline)
Colored inline label. Colors: blue, green, red, yellow, default.
```
Status: :badge[Active]{color="green"} or :badge[Deprecated]{color="red"}
```

### `callout` (block)
Callout box with a leading emoji.
```
::callout{emoji="💡"}
A helpful tip for the reader.
::
```

### `steps` + `step` (block, nested)
Numbered step-by-step instructions.
```
::steps
:::step{title="Install"}
Run \`pnpm add comark\`
:::
:::step{title="Configure"}
Add your components.
:::
::
```

### `tabs` (block)
Tabbed content panel. List tab names in the `tabs` prop (comma-separated). Content goes in default slot and `#tab1`, `#tab2`, etc.
```
::tabs{tabs="React,Vue,Svelte"}
React example code here (first tab = default slot)

#tab1
Vue example code here

#tab2
Svelte example code here
::
```

### `divider` (block)
Horizontal divider with optional label.
```
::divider{label="Section Break"}::
```

---

## Built-in Features (no component needed)

### GitHub-style Alerts
```
> [!NOTE]
> Useful information.

> [!TIP]
> Helpful advice.

> [!WARNING]
> Urgent information.

> [!CAUTION]
> Negative consequences.
```

### Math (if math plugin enabled)
- Inline: `$E = mc^2$`
- Display: `$$\\int_0^1 x^2 dx$$`

### Mermaid Diagrams (if mermaid plugin enabled)
```
\`\`\`mermaid
graph TD
    A --> B --> C
\`\`\`
```

---

## Guidelines

- Prefer semantic components over raw HTML.
- Use `alert` for important callouts, not raw blockquotes.
- Use `steps` for tutorials and how-to guides.
- Use `tabs` to show alternatives (e.g., different languages or package managers).
- Use `badge` inline to highlight statuses, labels, or tags.
- Use `card` to visually group related content with a title.
- Use standard Markdown for everything else (headings, paragraphs, lists, code, links, images, tables).
- Never output raw HTML. Always use Markdown or MDC components.