comark 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/internal/frontmatter.d.ts +1 -0
- package/dist/internal/frontmatter.js +4 -2
- package/dist/internal/parse/auto-close/index.js +69 -31
- package/dist/internal/parse/auto-close/table.js +12 -9
- package/dist/internal/parse/auto-unwrap.js +6 -10
- package/dist/internal/parse/html/html_block_rule.js +10 -16
- package/dist/internal/parse/html/html_inline_rule.js +3 -7
- package/dist/internal/parse/html/html_re.js +1 -1
- package/dist/internal/parse/html/index.d.ts +1 -0
- package/dist/internal/parse/html/index.js +15 -3
- package/dist/internal/parse/syntax/block-params.d.ts +9 -0
- package/dist/internal/parse/syntax/block-params.js +48 -0
- package/dist/internal/parse/syntax/brackets.d.ts +8 -0
- package/dist/internal/parse/syntax/brackets.js +20 -0
- package/dist/internal/parse/syntax/props.d.ts +5 -0
- package/dist/internal/parse/syntax/props.js +119 -0
- package/dist/internal/parse/token-processor.js +89 -50
- package/dist/internal/props-validation.js +4 -9
- package/dist/internal/stringify/attributes.d.ts +7 -0
- package/dist/internal/stringify/attributes.js +56 -1
- package/dist/internal/stringify/handlers/a.js +1 -3
- package/dist/internal/stringify/handlers/blockquote.js +19 -4
- package/dist/internal/stringify/handlers/code.js +1 -3
- package/dist/internal/stringify/handlers/emphesis.js +1 -3
- package/dist/internal/stringify/handlers/heading.js +6 -1
- package/dist/internal/stringify/handlers/html.js +34 -18
- package/dist/internal/stringify/handlers/img.js +1 -3
- package/dist/internal/stringify/handlers/li.js +18 -9
- package/dist/internal/stringify/handlers/mdc.js +3 -4
- package/dist/internal/stringify/handlers/ol.js +12 -2
- package/dist/internal/stringify/handlers/p.d.ts +1 -1
- package/dist/internal/stringify/handlers/p.js +8 -1
- package/dist/internal/stringify/handlers/pre.js +20 -14
- package/dist/internal/stringify/handlers/strong.js +1 -3
- package/dist/internal/stringify/handlers/table.js +14 -5
- package/dist/internal/stringify/handlers/template.js +5 -2
- package/dist/internal/stringify/handlers/ul.js +12 -2
- package/dist/internal/stringify/state.js +1 -1
- package/dist/internal/yaml.js +1 -1
- package/dist/parse.d.ts +4 -4
- package/dist/parse.js +20 -10
- package/dist/plugins/alert.d.ts +1 -1
- package/dist/plugins/alert.js +1 -1
- package/dist/plugins/binding.d.ts +1 -1
- package/dist/plugins/binding.js +1 -3
- package/dist/plugins/breaks.d.ts +1 -1
- package/dist/plugins/breaks.js +1 -1
- package/dist/plugins/emoji.d.ts +1 -1
- package/dist/plugins/emoji.js +8 -8
- package/dist/plugins/footnotes.d.ts +1 -1
- package/dist/plugins/footnotes.js +19 -13
- package/dist/plugins/headings.d.ts +19 -8
- package/dist/plugins/headings.js +27 -19
- package/dist/plugins/highlight.d.ts +2 -12
- package/dist/plugins/highlight.js +201 -103
- package/dist/plugins/json-render.d.ts +1 -1
- package/dist/plugins/json-render.js +5 -9
- package/dist/plugins/math.d.ts +1 -1
- package/dist/plugins/math.js +4 -6
- package/dist/plugins/mermaid.d.ts +1 -1
- package/dist/plugins/mermaid.js +6 -20
- package/dist/plugins/punctuation.d.ts +1 -1
- package/dist/plugins/punctuation.js +5 -6
- package/dist/plugins/security.d.ts +1 -1
- package/dist/plugins/security.js +2 -2
- package/dist/plugins/summary.d.ts +4 -1
- package/dist/plugins/syntax.d.ts +49 -0
- package/dist/plugins/syntax.js +558 -0
- package/dist/plugins/task-list.d.ts +2 -2
- package/dist/plugins/task-list.js +11 -8
- package/dist/plugins/toc.d.ts +3 -1
- package/dist/plugins/toc.js +1 -1
- package/dist/types.d.ts +57 -12
- package/dist/utils/comark.tmLanguage.d.ts +335 -0
- package/dist/utils/comark.tmLanguage.js +597 -0
- package/dist/utils/helpers.d.ts +16 -4
- package/dist/utils/helpers.js +16 -6
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.js +25 -3
- package/package.json +40 -40
- package/skills/comark/references/rendering-svelte.md +51 -7
- package/dist/internal/stringify/indent.d.ts +0 -5
- package/dist/internal/stringify/indent.js +0 -9
- package/dist/vite.d.ts +0 -1
- package/dist/vite.js +0 -1
- package/skills/skills/comark/AGENTS.md +0 -261
- package/skills/skills/comark/SKILL.md +0 -489
- package/skills/skills/comark/references/markdown-syntax.md +0 -599
- package/skills/skills/comark/references/parsing-ast.md +0 -378
- package/skills/skills/comark/references/rendering-react.md +0 -445
- package/skills/skills/comark/references/rendering-svelte.md +0 -453
- package/skills/skills/comark/references/rendering-vue.md +0 -462
- /package/skills/{skills/migrate-mdc-to-comark → migrate-mdc-to-comark}/SKILL.md +0 -0
|
@@ -1,489 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: comark
|
|
3
|
-
description: >-
|
|
4
|
-
Comark (Components in Markdown) parser — syntax, AST, Vue/React/Svelte renderers, plugins, and LLM streaming with auto-close.
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# Comark - Skills Guide
|
|
8
|
-
|
|
9
|
-
A high-performance markdown parser with Comark (Components in Markdown) support, built on markdown-it, offering both string-based and streaming APIs.
|
|
10
|
-
|
|
11
|
-
## Overview
|
|
12
|
-
|
|
13
|
-
**Comark** extends standard markdown with a powerful component system while maintaining full compatibility with CommonMark and GitHub Flavored Markdown. It provides:
|
|
14
|
-
|
|
15
|
-
- 🚀 **High-performance parsing** with markdown-it engine
|
|
16
|
-
- 📦 **Streaming support** with buffered and incremental modes
|
|
17
|
-
- ⚡ **Real-time rendering** with auto-close for incomplete syntax
|
|
18
|
-
- 🔧 **Comark component syntax** for custom components
|
|
19
|
-
- 🎨 **Vue, React & Svelte renderers** with custom component mapping
|
|
20
|
-
- 📝 **YAML frontmatter** support
|
|
21
|
-
- 📑 **Automatic TOC generation**
|
|
22
|
-
- 🎯 **Full TypeScript support**
|
|
23
|
-
- 🌈 **Syntax highlighting** with Shiki integration
|
|
24
|
-
|
|
25
|
-
## Package Information
|
|
26
|
-
|
|
27
|
-
- **Package Name:** `comark`
|
|
28
|
-
- **Installation:** `npm install comark` or `pnpm add comark`
|
|
29
|
-
- **Exports:**
|
|
30
|
-
- Main parser: `comark`
|
|
31
|
-
- Vue components: `@comark/vue`
|
|
32
|
-
- React components: `@comark/react`
|
|
33
|
-
- Svelte components: `@comark/svelte`
|
|
34
|
-
- HTML rendering: `@comark/html`
|
|
35
|
-
- ANSI terminal rendering: `@comark/ansi`
|
|
36
|
-
- Nuxt module: `@comark/nuxt`
|
|
37
|
-
|
|
38
|
-
## Quick Start
|
|
39
|
-
|
|
40
|
-
### Basic Usage
|
|
41
|
-
|
|
42
|
-
```typescript
|
|
43
|
-
import { parse } from 'comark'
|
|
44
|
-
|
|
45
|
-
const content = `---
|
|
46
|
-
title: Hello World
|
|
47
|
-
---
|
|
48
|
-
|
|
49
|
-
# Hello World
|
|
50
|
-
|
|
51
|
-
This is **markdown** with :icon component.
|
|
52
|
-
|
|
53
|
-
::alert{type="info"}
|
|
54
|
-
Important message
|
|
55
|
-
::
|
|
56
|
-
`
|
|
57
|
-
|
|
58
|
-
const result = await parse(content)
|
|
59
|
-
console.log(result.nodes) // Comark AST
|
|
60
|
-
console.log(result.frontmatter) // { title: 'Hello World' }
|
|
61
|
-
console.log(result.meta) // Additional metadata
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
### Vue Rendering
|
|
65
|
-
|
|
66
|
-
```vue
|
|
67
|
-
<template>
|
|
68
|
-
<Comark :markdown="content" />
|
|
69
|
-
</template>
|
|
70
|
-
|
|
71
|
-
<script setup lang="ts">
|
|
72
|
-
import { Comark } from '@comark/vue'
|
|
73
|
-
|
|
74
|
-
const content = `# Hello World`
|
|
75
|
-
</script>
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
### React Rendering
|
|
79
|
-
|
|
80
|
-
```tsx
|
|
81
|
-
import { Comark } from '@comark/react'
|
|
82
|
-
|
|
83
|
-
export default function App() {
|
|
84
|
-
return <Comark markdown={content} />
|
|
85
|
-
}
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
### Svelte Rendering
|
|
89
|
-
|
|
90
|
-
```svelte
|
|
91
|
-
<script lang="ts">
|
|
92
|
-
import { Comark } from '@comark/svelte'
|
|
93
|
-
|
|
94
|
-
const content = `# Hello World`
|
|
95
|
-
</script>
|
|
96
|
-
|
|
97
|
-
<Comark markdown={content} />
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
## Documentation Sections
|
|
101
|
-
|
|
102
|
-
This guide is organized into focused sections covering different aspects of the package:
|
|
103
|
-
|
|
104
|
-
### 📝 [1. Markdown Syntax](./references/markdown-syntax.md)
|
|
105
|
-
|
|
106
|
-
Learn how to write Comark documents with complete syntax reference:
|
|
107
|
-
|
|
108
|
-
- **Standard Markdown:** headings, text formatting, lists, links, images, blockquotes
|
|
109
|
-
- **Frontmatter:** YAML metadata with special fields (title, depth, searchDepth)
|
|
110
|
-
- **Comark Components:** block components (`::component`), inline components (`:component`), properties, slots, nesting
|
|
111
|
-
- **Attributes:** custom attributes on native markdown elements using `{...}` syntax
|
|
112
|
-
- **Code Blocks:** language specification, filename metadata, line highlighting, special characters
|
|
113
|
-
- **Task Lists:** GFM-style checkboxes with `[x]` and `[ ]` syntax
|
|
114
|
-
- **Tables:** GFM tables with alignment and inline markdown support
|
|
115
|
-
|
|
116
|
-
**[→ Read Full Markdown Syntax Guide](./references/markdown-syntax.md)**
|
|
117
|
-
|
|
118
|
-
---
|
|
119
|
-
|
|
120
|
-
### 🔧 [2. Parsing & AST Generation](./references/parsing-ast.md)
|
|
121
|
-
|
|
122
|
-
Complete guide for parsing documents and working with AST:
|
|
123
|
-
|
|
124
|
-
- **String Parsing:** `parse()` function with options (autoUnwrap, autoClose)
|
|
125
|
-
- **Async Parsing:** `parse()` with Shiki syntax highlighting
|
|
126
|
-
- **AST Structure:** Comark AST format - lightweight array-based AST
|
|
127
|
-
- **Rendering AST:** convert to HTML (`renderHTML` via `@comark/html`) or markdown (`renderMarkdown` via `comark/render`)
|
|
128
|
-
- **Auto-close:** automatic closing of unclosed syntax
|
|
129
|
-
- **Auto-unwrap:** remove unnecessary paragraph wrappers from container components
|
|
130
|
-
|
|
131
|
-
**[→ Read Full Parsing & AST Guide](./references/parsing-ast.md)**
|
|
132
|
-
|
|
133
|
-
---
|
|
134
|
-
|
|
135
|
-
### ⚛️ [3. Vue Rendering](./references/rendering-vue.md)
|
|
136
|
-
|
|
137
|
-
Comprehensive guide for rendering in Vue applications:
|
|
138
|
-
|
|
139
|
-
- **Basic Usage:** `Comark` component setup
|
|
140
|
-
- **Custom Components:** mapping custom Vue components to Comark elements
|
|
141
|
-
- **Dynamic Loading:** `componentsManifest` for lazy-loaded components
|
|
142
|
-
- **Slots Support:** named slots with `#slot-name` syntax
|
|
143
|
-
- **Streaming Mode:** real-time rendering with reactive content
|
|
144
|
-
- **Prose Components:** pre-built styled components for standard elements
|
|
145
|
-
- **Error Handling:** built-in error capture for streaming scenarios
|
|
146
|
-
- **Props Access:** accessing `__node` and parsed properties
|
|
147
|
-
|
|
148
|
-
**[→ Read Full Vue Rendering Guide](./references/rendering-vue.md)**
|
|
149
|
-
|
|
150
|
-
---
|
|
151
|
-
|
|
152
|
-
### ⚛️ [4. React Rendering](./references/rendering-react.md)
|
|
153
|
-
|
|
154
|
-
Comprehensive guide for rendering in React applications:
|
|
155
|
-
|
|
156
|
-
- **Basic Usage:** `Comark` component setup
|
|
157
|
-
- **Custom Components:** mapping custom React components to Comark elements
|
|
158
|
-
- **Dynamic Loading:** `componentsManifest` for lazy-loaded components
|
|
159
|
-
- **Props Conversion:** automatic HTML attribute conversion (`class` → `className`, etc.)
|
|
160
|
-
- **Streaming Mode:** real-time rendering with reactive content
|
|
161
|
-
- **Prose Components:** pre-built styled components for standard elements
|
|
162
|
-
- **Custom Props:** accessing parsed properties and `__node`
|
|
163
|
-
- **CSS Class Name:** custom wrapper classes and Tailwind CSS integration
|
|
164
|
-
|
|
165
|
-
**[→ Read Full React Rendering Guide](./references/rendering-react.md)**
|
|
166
|
-
|
|
167
|
-
---
|
|
168
|
-
|
|
169
|
-
### 🎡 [5. Svelte Rendering](./references/rendering-svelte.md)
|
|
170
|
-
|
|
171
|
-
Comprehensive guide for rendering in Svelte 5 applications:
|
|
172
|
-
|
|
173
|
-
- **Basic Usage:** `Comark` component setup with `$state`
|
|
174
|
-
- **Custom Components:** mapping custom Svelte components to Comark elements
|
|
175
|
-
- **Dynamic Loading:** `componentsManifest` for lazy-loaded components
|
|
176
|
-
- **Props Mapping:** attribute-to-prop conversion (close to HTML semantics)
|
|
177
|
-
- **Streaming Mode:** real-time rendering with reactive `$state`
|
|
178
|
-
- **Experimental Async:** `ComarkAsync` with `<svelte:boundary>`
|
|
179
|
-
- **Prose Components:** `Prose` prefix for overriding native HTML elements
|
|
180
|
-
|
|
181
|
-
**[→ Read Full Svelte Rendering Guide](./references/rendering-svelte.md)**
|
|
182
|
-
|
|
183
|
-
---
|
|
184
|
-
|
|
185
|
-
### 🤖 [6. Using with AI Agents](./AGENTS.md)
|
|
186
|
-
|
|
187
|
-
Guide for integrating Comark in AI agent and LLM streaming workflows:
|
|
188
|
-
|
|
189
|
-
- **Streaming from LLMs:** rendering incremental AI output in real time
|
|
190
|
-
- **Auto-Close:** handling incomplete syntax from partial LLM tokens
|
|
191
|
-
- **Caret Indicator:** showing a live cursor during generation
|
|
192
|
-
- **Framework Examples:** Vue, React, Svelte streaming patterns
|
|
193
|
-
- **ANSI for CLIs:** rendering AI output in terminal agents
|
|
194
|
-
|
|
195
|
-
**[→ Read Full Agents Guide](./AGENTS.md)**
|
|
196
|
-
|
|
197
|
-
---
|
|
198
|
-
|
|
199
|
-
## Key Features Deep Dive
|
|
200
|
-
|
|
201
|
-
### Comark Component Syntax
|
|
202
|
-
|
|
203
|
-
Comark extends markdown with custom components while preserving readability:
|
|
204
|
-
|
|
205
|
-
```markdown
|
|
206
|
-
<!-- Block Component -->
|
|
207
|
-
::alert{type="warning" .important}
|
|
208
|
-
This is a **warning** message with markdown support.
|
|
209
|
-
::
|
|
210
|
-
|
|
211
|
-
<!-- Inline Component -->
|
|
212
|
-
Check out this :icon-star{.text-yellow} component.
|
|
213
|
-
|
|
214
|
-
<!-- Component with Slots -->
|
|
215
|
-
::card
|
|
216
|
-
#header
|
|
217
|
-
## Title
|
|
218
|
-
|
|
219
|
-
#content
|
|
220
|
-
Main content
|
|
221
|
-
|
|
222
|
-
#footer
|
|
223
|
-
Footer
|
|
224
|
-
::
|
|
225
|
-
```
|
|
226
|
-
|
|
227
|
-
### Comark AST Format
|
|
228
|
-
|
|
229
|
-
Lightweight array-based structure for efficient processing:
|
|
230
|
-
|
|
231
|
-
```typescript
|
|
232
|
-
interface ComarkTree {
|
|
233
|
-
nodes: [
|
|
234
|
-
["h1", { "id": "hello" }, "Hello"],
|
|
235
|
-
["p", {}, "Text with ", ["strong", {}, "bold"], " word"],
|
|
236
|
-
["alert", { "type": "info" }, "Message"]
|
|
237
|
-
],
|
|
238
|
-
frontmatter: {},
|
|
239
|
-
meta: {}
|
|
240
|
-
}
|
|
241
|
-
```
|
|
242
|
-
|
|
243
|
-
## Common Use Cases
|
|
244
|
-
|
|
245
|
-
### 1. Static Site Generator
|
|
246
|
-
|
|
247
|
-
```typescript
|
|
248
|
-
import { parse } from 'comark'
|
|
249
|
-
import { renderHTML } from '@comark/html'
|
|
250
|
-
import highlight from '@comark/html/plugins/highlight'
|
|
251
|
-
|
|
252
|
-
async function processMarkdownFile(filePath: string) {
|
|
253
|
-
const content = await readFile(filePath, 'utf-8')
|
|
254
|
-
|
|
255
|
-
const tree = await parse(content, {
|
|
256
|
-
plugins: [
|
|
257
|
-
highlight({
|
|
258
|
-
themes: { light: 'github-dark', dark: 'github-dark' },
|
|
259
|
-
}),
|
|
260
|
-
],
|
|
261
|
-
})
|
|
262
|
-
|
|
263
|
-
return {
|
|
264
|
-
html: renderHTML(tree),
|
|
265
|
-
frontmatter: tree.frontmatter,
|
|
266
|
-
toc: tree.meta.toc
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
```
|
|
270
|
-
|
|
271
|
-
### 2. Real-time Markdown Editor
|
|
272
|
-
|
|
273
|
-
```tsx
|
|
274
|
-
import { useState } from 'react'
|
|
275
|
-
import { Comark } from '@comark/react'
|
|
276
|
-
|
|
277
|
-
export default function Editor() {
|
|
278
|
-
const [content, setContent] = useState('# Hello')
|
|
279
|
-
|
|
280
|
-
return (
|
|
281
|
-
<div className="split-editor">
|
|
282
|
-
<textarea value={content} onChange={e => setContent(e.target.value)} />
|
|
283
|
-
<Comark markdown={content} />
|
|
284
|
-
</div>
|
|
285
|
-
)
|
|
286
|
-
}
|
|
287
|
-
```
|
|
288
|
-
|
|
289
|
-
### 3. Batch File Processing
|
|
290
|
-
|
|
291
|
-
```typescript
|
|
292
|
-
import { readFile } from 'node:fs/promises'
|
|
293
|
-
import { parse } from 'comark'
|
|
294
|
-
|
|
295
|
-
async function processMultipleFiles(files: string[]) {
|
|
296
|
-
const results = await Promise.all(
|
|
297
|
-
files.map(async (file) => {
|
|
298
|
-
const content = await readFile(file, 'utf-8')
|
|
299
|
-
return await parse(content)
|
|
300
|
-
})
|
|
301
|
-
)
|
|
302
|
-
|
|
303
|
-
results.forEach((result, i) => {
|
|
304
|
-
console.log(`File ${files[i]}:`)
|
|
305
|
-
console.log(` - ${result.nodes.length} nodes`)
|
|
306
|
-
})
|
|
307
|
-
}
|
|
308
|
-
```
|
|
309
|
-
|
|
310
|
-
### 4. Documentation Platform
|
|
311
|
-
|
|
312
|
-
```vue
|
|
313
|
-
<template>
|
|
314
|
-
<article class="prose">
|
|
315
|
-
<Comark :markdown="markdownContent" :components="docComponents" />
|
|
316
|
-
</article>
|
|
317
|
-
</template>
|
|
318
|
-
|
|
319
|
-
<script setup lang="ts">
|
|
320
|
-
import { Comark } from '@comark/vue'
|
|
321
|
-
import { docComponents } from './components'
|
|
322
|
-
</script>
|
|
323
|
-
```
|
|
324
|
-
|
|
325
|
-
## API Reference Summary
|
|
326
|
-
|
|
327
|
-
### Core Functions (`comark`)
|
|
328
|
-
|
|
329
|
-
```typescript
|
|
330
|
-
// Asynchronous parsing
|
|
331
|
-
parse(source: string, options?: ParseOptions): Promise<ComarkTree>
|
|
332
|
-
|
|
333
|
-
// Auto-close unclosed syntax
|
|
334
|
-
autoCloseMarkdown(source: string): string
|
|
335
|
-
```
|
|
336
|
-
|
|
337
|
-
### HTML Rendering Functions (`@comark/html`)
|
|
338
|
-
|
|
339
|
-
```typescript
|
|
340
|
-
// Render markdown to HTML string (parse + render in one step)
|
|
341
|
-
render(markdown: string, options?: RenderOptions): Promise<string>
|
|
342
|
-
|
|
343
|
-
// Render a pre-parsed tree to HTML
|
|
344
|
-
renderHTML(tree: ComarkTree, options?: RenderOptions): Promise<string>
|
|
345
|
-
|
|
346
|
-
// Create a reusable render function with shared parser instance
|
|
347
|
-
createRender(options?: ParseOptions & RenderOptions): (markdown: string) => Promise<string>
|
|
348
|
-
```
|
|
349
|
-
|
|
350
|
-
### Vue Components (`@comark/vue`)
|
|
351
|
-
|
|
352
|
-
```vue
|
|
353
|
-
<Comark :markdown="markdownString" :components="customComponents" />
|
|
354
|
-
```
|
|
355
|
-
|
|
356
|
-
### React Components (`@comark/react`)
|
|
357
|
-
|
|
358
|
-
```tsx
|
|
359
|
-
<Comark markdown={markdownString} components={customComponents} />
|
|
360
|
-
```
|
|
361
|
-
|
|
362
|
-
### Svelte Components (`@comark/svelte`)
|
|
363
|
-
|
|
364
|
-
```svelte
|
|
365
|
-
<Comark markdown={markdownString} components={customComponents} />
|
|
366
|
-
```
|
|
367
|
-
|
|
368
|
-
## Performance Characteristics
|
|
369
|
-
|
|
370
|
-
- **Comark AST format** - lightweight array-based AST
|
|
371
|
-
- **Lazy component loading** - only load what's needed
|
|
372
|
-
- **Shiki highlighter caching** - avoid re-initialization
|
|
373
|
-
- **Parallel processing** - batch parse multiple files efficiently
|
|
374
|
-
|
|
375
|
-
## TypeScript Support
|
|
376
|
-
|
|
377
|
-
Full TypeScript definitions included:
|
|
378
|
-
|
|
379
|
-
```typescript
|
|
380
|
-
import type {
|
|
381
|
-
ComarkTree,
|
|
382
|
-
ComarkNode,
|
|
383
|
-
ParseOptions,
|
|
384
|
-
} from 'comark'
|
|
385
|
-
```
|
|
386
|
-
|
|
387
|
-
## Architecture Overview
|
|
388
|
-
|
|
389
|
-
```
|
|
390
|
-
┌─────────────────────────────────────────┐
|
|
391
|
-
│ Markdown Input (String) │
|
|
392
|
-
└────────────────┬────────────────────────┘
|
|
393
|
-
│
|
|
394
|
-
┌────────▼────────┐
|
|
395
|
-
│ Auto-close │ (Optional)
|
|
396
|
-
│ Unclosed │
|
|
397
|
-
│ Syntax │
|
|
398
|
-
└────────┬────────┘
|
|
399
|
-
│
|
|
400
|
-
┌────────▼────────┐
|
|
401
|
-
│ Parse │
|
|
402
|
-
│ Frontmatter │ (YAML)
|
|
403
|
-
└────────┬────────┘
|
|
404
|
-
│
|
|
405
|
-
┌────────▼────────┐
|
|
406
|
-
│ MarkdownIt │
|
|
407
|
-
│ + Plugins │ (Comark, Tasks)
|
|
408
|
-
└────────┬────────┘
|
|
409
|
-
│
|
|
410
|
-
┌────────▼────────┐
|
|
411
|
-
│ Token │
|
|
412
|
-
│ Processing │
|
|
413
|
-
└────────┬────────┘
|
|
414
|
-
│
|
|
415
|
-
┌────────▼────────┐
|
|
416
|
-
│ Comark │
|
|
417
|
-
│ AST │
|
|
418
|
-
└────────┬────────┘
|
|
419
|
-
│
|
|
420
|
-
┌────────▼────────┐
|
|
421
|
-
│ Auto-unwrap │ (Optional)
|
|
422
|
-
└────────┬────────┘
|
|
423
|
-
│
|
|
424
|
-
┌────────▼────────┐
|
|
425
|
-
│ Generate TOC │
|
|
426
|
-
└────────┬────────┘
|
|
427
|
-
│
|
|
428
|
-
┌────────▼────────┐
|
|
429
|
-
│ ComarkTree │
|
|
430
|
-
│ (nodes + data │
|
|
431
|
-
│ + meta) │
|
|
432
|
-
└────────┬────────┘
|
|
433
|
-
│
|
|
434
|
-
┌───────────┬───────────┴───────────┐
|
|
435
|
-
▼ ▼ ▼
|
|
436
|
-
┌─────────┐ ┌─────────┐ ┌─────────┐
|
|
437
|
-
│ Vue │ │ React │ │ Svelte │
|
|
438
|
-
│ Renderer│ │ Renderer│ │ Renderer│
|
|
439
|
-
└─────────┘ └─────────┘ └─────────┘
|
|
440
|
-
```
|
|
441
|
-
|
|
442
|
-
## Contributing & Testing
|
|
443
|
-
|
|
444
|
-
See the [test specifications](../../packages/comark/SPEC/) for examples of all supported syntax features.
|
|
445
|
-
|
|
446
|
-
Run tests:
|
|
447
|
-
```bash
|
|
448
|
-
pnpm test
|
|
449
|
-
```
|
|
450
|
-
|
|
451
|
-
Run specific test:
|
|
452
|
-
```bash
|
|
453
|
-
pnpm test -- tests/parse.test.ts
|
|
454
|
-
```
|
|
455
|
-
|
|
456
|
-
## Resources
|
|
457
|
-
|
|
458
|
-
- **README:** [README.md](../../README.md) - Installation and quick start
|
|
459
|
-
- **Specifications:** [SPEC/](../../packages/comark/SPEC/) - Complete syntax test cases
|
|
460
|
-
|
|
461
|
-
---
|
|
462
|
-
|
|
463
|
-
## Summary
|
|
464
|
-
|
|
465
|
-
**Comark** is a comprehensive solution for parsing and rendering markdown with component support. It excels at:
|
|
466
|
-
|
|
467
|
-
1. **Extending Markdown** - Component syntax without breaking compatibility
|
|
468
|
-
2. **Streaming Support** - Real-time rendering with auto-close
|
|
469
|
-
3. **Lightweight AST** - Efficient Comark AST format
|
|
470
|
-
4. **Framework Support** - First-class Vue, React, and Svelte integration
|
|
471
|
-
5. **Developer Experience** - Full TypeScript support and comprehensive documentation
|
|
472
|
-
|
|
473
|
-
**Choose Comark when you need:**
|
|
474
|
-
- Markdown with custom components
|
|
475
|
-
- Streaming/incremental parsing
|
|
476
|
-
- Real-time markdown editors
|
|
477
|
-
- AI-generated content rendering
|
|
478
|
-
- Documentation platforms
|
|
479
|
-
- Static site generation with custom components
|
|
480
|
-
|
|
481
|
-
---
|
|
482
|
-
|
|
483
|
-
**Next Steps:**
|
|
484
|
-
- 📝 [Learn Markdown Syntax](./references/markdown-syntax.md)
|
|
485
|
-
- 🔧 [Master Parsing & AST](./references/parsing-ast.md)
|
|
486
|
-
- ⚛️ [Explore Vue Rendering](./references/rendering-vue.md)
|
|
487
|
-
- ⚛️ [Explore React Rendering](./references/rendering-react.md)
|
|
488
|
-
- 🎡 [Explore Svelte Rendering](./references/rendering-svelte.md)
|
|
489
|
-
- 🤖 [Use with AI Agents](./AGENTS.md)
|