`
- **Streaming Mode:** real-time rendering with caret indicator
- **Data Binding:** `:binding` resolution with ambient `data` input
- **Pre-configured Components:** `defineMarkdownComponent` and `defineMarkdownDocumentComponent`
- **Plugins:** Math (KaTeX), Mermaid, Binding with Angular component wrappers
**[β Read Full Angular Rendering Guide](./references/rendering-angular.md)**
---
### π€ [7. Using with AI Agents](./AGENTS.md)
Guide for integrating Comark in AI agent and LLM streaming workflows:
- **Streaming from LLMs:** rendering incremental AI output in real time
- **Auto-Close:** handling incomplete syntax from partial LLM tokens
- **Caret Indicator:** showing a live cursor during generation
- **Framework Examples:** Vue, React, Svelte, Angular streaming patterns
- **ANSI for CLIs:** rendering AI output in terminal agents
**[β Read Full Agents Guide](./AGENTS.md)**
---
## Key Features Deep Dive
### Comark Component Syntax
Comark extends markdown with custom components while preserving readability:
```markdown
::alert{type="warning" .important}
This is a **warning** message with markdown support.
::
Check out this :icon-star{.text-yellow} component.
::card
#header
## Title
#content
Main content
#footer
Footer
::
```
### Markdown Document Model
Lightweight array-based structure for efficient processing:
```typescript
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
```typescript
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. Real-time Markdown Editor
```tsx
import { useState } from 'react'
import { Markdown } from '@comark/react'
export default function Editor() {
const [content, setContent] = useState('# Hello')
return (
)
}
```
### 3. Batch File Processing
```typescript
import { readFile } from 'node:fs/promises'
import { parseMarkdown } from 'comark'
async function processMultipleFiles(files: string[]) {
const results = await Promise.all(
files.map(async (file) => {
const content = await readFile(file, 'utf-8')
return await parseMarkdown(content)
})
)
results.forEach((result, i) => {
console.log(`File ${files[i]}:`)
console.log(` - ${result.nodes.length} nodes`)
})
}
```
### 4. Documentation Platform
```vue
```
## API Reference Summary
### Core Functions (`comark`)
```typescript
// Asynchronous parsing
parseMarkdown(source: string, options?: ParserOptions): Promise
// Auto-close unclosed syntax
autoCloseMarkdown(source: string): string
```
### HTML Rendering Functions (`@comark/html`)
```typescript
// Render markdown to HTML string (parse + render in one step)
renderHtml(markdown: string, options?: ParserOptions & RendererOptions): Promise
// Render a pre-parsed document to HTML
renderHtmlFromDocument(document: MarkdownDocument, options?: RendererOptions): Promise
// Create a reusable render function with shared parser instance
createHtmlRenderer(options?: ParserOptions & RendererOptions): (markdown: string) => Promise
```
### Vue Components (`@comark/vue`)
```vue
```
### React Components (`@comark/react`)
```tsx
```
### Svelte Components (`@comark/svelte`)
```svelte
```
### Angular Components (`@comark/angular`)
```html
```
## Performance Characteristics
- **Serializable document model** - compact array-based nodes
- **Lazy component loading** - only load what's needed
- **Shiki highlighter caching** - avoid re-initialization
- **Parallel processing** - batch parse multiple files efficiently
## TypeScript Support
Full TypeScript definitions included:
```typescript
import type {
MarkdownDocument,
Node,
ParserOptions,
} from 'comark'
```
## Architecture Overview
```
βββββββββββββββββββββββββββββββββββββββββββ
β Markdown Input (String) β
ββββββββββββββββββ¬βββββββββββββββββββββββββ
β
ββββββββββΌβββββββββ
β Auto-close β (Optional)
β Unclosed β
β Syntax β
ββββββββββ¬βββββββββ
β
ββββββββββΌβββββββββ
β Parse β
β Frontmatter β (YAML)
ββββββββββ¬βββββββββ
β
ββββββββββΌβββββββββ
β MarkdownIt β
β + Plugins β (Comark, Tasks)
ββββββββββ¬βββββββββ
β
ββββββββββΌβββββββββ
β Token β
β Processing β
ββββββββββ¬βββββββββ
β
ββββββββββΌβββββββββ
β Comark β
β AST β
ββββββββββ¬βββββββββ
β
ββββββββββΌβββββββββ
β Auto-unwrap β (Optional)
ββββββββββ¬βββββββββ
β
ββββββββββΌβββββββββ
β Generate TOC β
ββββββββββ¬βββββββββ
β
ββββββββββΌβββββββββ
β MarkdownDocument β
β (nodes + data β
β + meta) β
ββββββββββ¬βββββββββ
β
βββββββββββββ¬βββββββ΄βββββββ¬ββββββββββββ
βΌ βΌ βΌ βΌ
βββββββββββ βββββββββββ βββββββββββ βββββββββββ
β Vue β β React β β Svelte β β Angular β
β Rendererβ β Rendererβ β Rendererβ β Rendererβ
βββββββββββ βββββββββββ βββββββββββ βββββββββββ
```
## Contributing & Testing
See the [test specifications](../../packages/comark/SPEC/) for examples of all supported syntax features.
Run tests:
```bash
pnpm test
```
Run specific test:
```bash
pnpm test -- tests/parse.test.ts
```
## Resources
- **README:** [README.md](../../README.md) - Installation and quick start
- **Specifications:** [SPEC/](../../packages/comark/SPEC/) - Complete syntax test cases
---
## Summary
**Comark** is a comprehensive solution for parsing and rendering markdown with component support. It excels at:
1. **Extending Markdown** - Component syntax without breaking compatibility
2. **Streaming Support** - Real-time rendering with auto-close
3. **Serializable Documents** - Efficient `MarkdownDocument` model with compact nodes
4. **Framework Support** - First-class Vue, React, Svelte, and Angular integration
5. **Developer Experience** - Full TypeScript support and comprehensive documentation
**Choose Comark when you need:**
- Markdown with custom components
- Streaming/incremental parsing
- Real-time markdown editors
- AI-generated content rendering
- Documentation platforms
- Static site generation with custom components
---
**Next Steps:**
- π [Learn Markdown Syntax](./references/markdown-syntax.md)
- π§ [Master Parsing & AST](./references/parsing-ast.md)
- βοΈ [Explore Vue Rendering](./references/rendering-vue.md)
- βοΈ [Explore React Rendering](./references/rendering-react.md)
- π‘ [Explore Svelte Rendering](./references/rendering-svelte.md)
- π
°οΈ [Explore Angular Rendering](./references/rendering-angular.md)
- π€ [Use with AI Agents](./AGENTS.md)