Comark

From comarkdown/comark · View interactive version

Comark is an AI agent skill from the GitHub repository comarkdown/comark. Comark (Components in Markdown) parser: syntax, AST, Vue/React/Svelte/Angular renderers, plugins, and LLM streaming with auto-close.

How to use this skill

Skill file

Comark skill guide

Markdown parser and renderer with Comark (Components in Markdown) syntax, built on markdown-exit (a TypeScript rewrite of markdown-it). Parses CommonMark and GitHub Flavored Markdown into a compact, serializable document at build time, at runtime, or during a stream.

Overview

Comark extends Markdown with block and inline components, attributes, and plugins while parsing standard CommonMark and GitHub Flavored Markdown. Key features:

Package information

Quick start

Basic usage

import { parseMarkdown } from 'comark'

const content = `---
title: Hello World
---

# Hello World

This is **markdown** with :icon component.

::alert{type="info"}
Important message
::
`

const result = await parseMarkdown(content)
console.log(result.nodes)       // Markdown AST
console.log(result.frontmatter) // { title: 'Hello World' }
console.log(result.meta)    // Additional metadata

Vue rendering

<template>
  <Markdown :value="content" />
</template>

<script setup lang="ts">
import { Markdown } from '@comark/vue'

const content = `# Hello World`
</script>

React rendering

import { Markdown } from '@comark/react'

export default function App() {
  return <Markdown value={content} />
}

Svelte rendering

<script lang="ts">
  import { Markdown } from '@comark/svelte'

  const content = `# Hello World`
</script>

<Markdown value={content} />

Angular rendering

import { Component } from '@angular/core'
import { Markdown } from '@comark/angular'

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [Markdown],
  template: `<comark-markdown [value]="content" />`,
})
export class AppComponent {
  content = `# Hello World`
}

Documentation sections

Reference guides for each part of Comark:

[1. Markdown syntax](./references/markdown-syntax.md)

Syntax reference for authoring Comark documents:

Read the Markdown syntax guide


[2. Parsing and document model](./references/parsing-ast.md)

Parsing Markdown and working with MarkdownDocument:

Read the parsing and document model guide


[3. Vue rendering](./references/rendering-vue.md)

Rendering Comark in Vue 3 and Nuxt applications:

Read the Vue rendering guide


[4. React rendering](./references/rendering-react.md)

Rendering Comark in React and Next.js applications:

Read the React rendering guide


[5. Svelte rendering](./references/rendering-svelte.md)

Rendering Comark in Svelte 5 and SvelteKit applications:

Read the Svelte rendering guide


[6. Angular rendering](./references/rendering-angular.md)

Rendering Comark in Angular 21+ applications:

Read the Angular rendering guide


[7. Using with AI agents](./AGENTS.md)

Streaming LLM output with Comark:

Read the AI agents guide


Key features

Comark component syntax

Comark extends Markdown with custom block and inline components:

<!-- Block Component -->
::alert{type="warning" .important}
This is a **warning** message with markdown support.
::

<!-- Inline Component -->
Check out this :icon-star{.text-yellow} component.

<!-- Component with Slots -->
::card
#header
## Title

#content
Main content

#footer
Footer
::

Markdown document model

Compact tuple-based structure:

interface MarkdownDocument {
  nodes: [
    ["h1", { "id": "hello" }, "Hello"],
    ["p", {}, "Text with ", ["strong", {}, "bold"], " word"],
    ["alert", { "type": "info" }, "Message"]
  ],
  frontmatter: {},
  meta: {}
}

Common use cases

1. Static site generator

import { parseMarkdown } from 'comark'
import { renderHtmlFromDocument } from '@comark/html'
import shiki from '@comark/html/plugins/shiki'

async function processMarkdownFile(filePath: string) {
  const content = await readFile(filePath, 'utf-8')

  const doc = await parseMarkdown(content, {
    plugins: [
      shiki({
        themes: { light: 'github-dark', dark: 'github-dark' },
      }),
    ],
  })

  return {
    html: await renderHtmlFromDocument(doc),
    frontmatter: doc.frontmatter,
    toc: doc.meta.toc
  }
}

2. Live Markdown editor

import { useState } from 'react'
import { Markdown } from '@comark/react'

export default function Editor() {
  const [content, setContent] = useState('# Hello')

  return (
    <div className="split-editor">
      <textarea value={content} onChange={e => setContent(e.target.value)} />
      <Markdown value={content} />
    </div>
  )
}

3. Batch file processing

import { readFile } from 'node:fs/promises'
import { createMarkdownParser } from 'comark'

const parse = createMarkdownParser()

async function processMultipleFiles(files: string[]) {
  const results = await Promise.all(
    files.map(async (file) => {
      const content = await readFile(file, 'utf-8')
      return await parse(content)
    })
  )

  results.forEach((result, i) => {
    console.log(`File ${files[i]}:`)
    console.log(`  - ${result.nodes.length} nodes`)
  })
}

4. Documentation platform

<template>
  <article class="prose">
    <Markdown :value="markdownContent" :components="docComponents" />
  </article>
</template>

<script setup lang="ts">
import { Markdown } from '@comark/vue'
import { docComponents } from './components'
</script>

API reference summary

Core functions (`comark`)

// Parse Markdown to a MarkdownDocument
parseMarkdown(source: string, options?: ParserOptions): Promise<MarkdownDocument>

// Create a reusable parser instance
createMarkdownParser(options?: ParserOptions): (source: string) => Promise<MarkdownDocument>

// Auto-close unfinished syntax
autoCloseMarkdown(source: string, options?: AutoCloseOptions): string

HTML rendering functions (`@comark/html`)

// Parse and render Markdown to an HTML string
renderHtml(markdown: string, options?: ParserOptions & RendererOptions): Promise<string>

// Render a pre-parsed document to HTML
renderHtmlFromDocument(document: MarkdownDocument, options?: RendererOptions): Promise<string>

// Create a reusable render function with a shared parser instance
createHtmlRenderer(options?: ParserOptions & RendererOptions): (markdown: string) => Promise<string>

Vue components (`@comark/vue`)

<Markdown :value="markdownString" :components="customComponents" />

React components (`@comark/react`)

<Markdown value={markdownString} components={customComponents} />

Svelte components (`@comark/svelte`)

<Markdown value={markdownString} components={customComponents} />

Angular components (`@comark/angular`)

<comark-markdown [value]="markdownString" [components]="customComponents" />

Performance notes

TypeScript support

TypeScript definitions ship with comark and every renderer package:

import type {
  MarkdownDocument,
  Node,
  ElementNode,
  ParserOptions,
} from 'comark'

Architecture overview

Markdown input (string)
  -> autoCloseMarkdown (default: on)
  -> frontmatter extraction (YAML -> document.frontmatter)
  -> markdown-exit tokenization + plugins (components, attributes, task-list, alert, ...)
  -> token processor -> compact node tuples
  -> autoUnwrap + post plugins (for example shiki, toc, summary, security)
  -> MarkdownDocument { nodes, frontmatter, meta }
  -> renderer (@comark/vue, @comark/react, @comark/svelte, @comark/angular, @comark/html, @comark/ansi, comark/render)

Resources

Reference guides

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.