Skip to content

Commit fc94065

Browse files
farnabazatinux
andauthored
!refactor: rename <Comark> components to <Markdown> and more (#318)
Co-authored-by: Sébastien Chopin <atinux@gmail.com>
1 parent 83f67ae commit fc94065

310 files changed

Lines changed: 4625 additions & 4794 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

AGENTS.md

Lines changed: 46 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ Located at `packages/comark/`:
4646
```
4747
packages/comark/
4848
├── src/
49-
│ ├── index.ts # Core parser: parse(), autoCloseMarkdown()
50-
│ ├── render.ts # String rendering: renderMarkdown() (renderHTML moved to @comark/html)
51-
│ ├── types.ts # TypeScript interfaces (ParseOptions, etc.)
49+
│ ├── index.ts # Core parser: parseMarkdown(), autoCloseMarkdown()
50+
│ ├── render.ts # String rendering: renderMarkdown() (renderHtmlFromDocument() moved to @comark/html)
51+
│ ├── types.ts # TypeScript interfaces (ParserOptions, etc.)
5252
│ ├── ast/ # Comark AST types and utilities
5353
│ │ ├── index.ts # Re-exports (comark/ast entry point)
54-
│ │ ├── types.ts # ComarkTree, ComarkNode, ComarkElement, ComarkText
55-
│ │ └── utils.ts # textContent(), visit() tree utilities
54+
│ │ ├── types.ts # MarkdownDocument, Node, ElementNode, TextNode
55+
│ │ └── utils.ts # textContent(), visit() document utilities
5656
│ ├── plugins/ # Built-in and optional plugins
5757
│ │ ├── alert.ts # Alert/callout blocks
5858
│ │ ├── emoji.ts # Emoji shortcodes
@@ -99,21 +99,21 @@ Located at `packages/comark-html/`. Framework-free HTML string rendering.
9999
### Usage
100100

101101
```typescript
102-
import { render, renderHTML, createRender } from '@comark/html'
102+
import { createHtmlRenderer, renderHtml, renderHtmlFromDocument } from '@comark/html'
103103
import highlight from '@comark/html/plugins/highlight'
104104
import math, { Math } from '@comark/html/plugins/math'
105105

106-
// Flat options — ParseOptions & RenderOptions merged at top level
107-
const renderFn = createRender({
106+
// Flat options — ParserOptions & RendererOptions merged at top level
107+
const renderHtml = createHtmlRenderer({
108108
plugins: [highlight({ themes: { light: 'github-light', dark: 'github-dark' } })],
109109
components: {
110110
Math,
111-
alert: ([, attrs, ...children], { render }) =>
112-
`<div class="alert alert-${attrs.type}">${render(children)}</div>`
111+
alert: async ([, attrs, ...children], { render }) =>
112+
`<div class="alert alert-${attrs.type}">${await render(children)}</div>`
113113
},
114114
})
115115

116-
const html = await renderFn(markdownString)
116+
const html = await renderHtml(markdownString)
117117
```
118118

119119
---
@@ -135,20 +135,20 @@ Located at `packages/comark-ansi/`. ANSI terminal renderer.
135135
### Usage
136136

137137
```typescript
138-
import { log, render, renderANSI, createLog, createRender } from '@comark/ansi'
138+
import { createAnsiRenderer, createAnsiWriter, renderAnsi, renderAnsiFromDocument, writeAnsi } from '@comark/ansi'
139139
import highlight from '@comark/ansi/plugins/highlight'
140140
import math, { Math } from '@comark/ansi/plugins/math'
141141

142-
// Flat options — ParseOptions & RenderANSIOptions merged at top level
143-
const logFn = createLog({
142+
// Flat options — ParserOptions & AnsiRendererOptions merged at top level
143+
const writeAnsi = createAnsiWriter({
144144
plugins: [highlight(), math()],
145145
components: { Math },
146146
width: 120, // terminal width
147147
colors: true, // emit ANSI escape codes
148-
write: (s) => process.stderr.write(s),
148+
writer: (output) => process.stderr.write(output),
149149
})
150150

151-
await logFn(markdownString)
151+
await writeAnsi(markdownString)
152152
```
153153

154154
---
@@ -163,7 +163,7 @@ packages/comark-vue/
163163
│ ├── index.ts # Entry point
164164
│ ├── components/
165165
│ │ ├── Markdown.ts # High-level markdown → render component
166-
│ │ ├── MarkdownParsed.ts # Low-level AST → render component
166+
│ │ ├── MarkdownDocument.ts # Low-level AST → render component
167167
│ │ ├── Math.ts # Math rendering component
168168
│ │ └── Mermaid.ts # Mermaid rendering component
169169
│ └── plugins/
@@ -185,7 +185,7 @@ packages/comark-vue/
185185
### Usage
186186

187187
```typescript
188-
import { Markdown, MarkdownParsed, defineMarkdownComponent } from '@comark/vue'
188+
import { Markdown, MarkdownDocument, defineMarkdownComponent } from '@comark/vue'
189189
import math, { Math } from '@comark/vue/plugins/math'
190190
import mermaid, { Mermaid } from '@comark/vue/plugins/mermaid'
191191
```
@@ -200,10 +200,9 @@ packages/comark-react/
200200
│ ├── index.ts # Entry point
201201
│ ├── components/
202202
│ │ ├── Markdown.tsx # High-level markdown → render component
203-
│ │ ├── MarkdownParsed.tsx # Low-level AST → render component
203+
│ │ ├── MarkdownDocument.tsx # Low-level AST → render component
204204
│ │ ├── MarkdownClient.tsx # Client-only markdown component
205205
│ │ ├── MarkdownLive.tsx # Streaming/live markdown component
206-
│ │ ├── Comark*.tsx # Deprecated wrappers for the old component names
207206
│ │ ├── Math.tsx # Math rendering component
208207
│ │ └── Mermaid.tsx # Mermaid rendering component
209208
│ └── plugins/
@@ -225,7 +224,7 @@ packages/comark-react/
225224
### Usage
226225

227226
```typescript
228-
import { Markdown, MarkdownParsed, defineMarkdownComponent } from '@comark/react'
227+
import { Markdown, MarkdownDocument, defineMarkdownComponent } from '@comark/react'
229228
import math, { Math } from '@comark/react/plugins/math'
230229
import mermaid, { Mermaid } from '@comark/react/plugins/mermaid'
231230
```
@@ -241,15 +240,13 @@ packages/comark-svelte/
241240
│ ├── types.ts # Shared prop interfaces
242241
│ ├── components/
243242
│ │ ├── Markdown.svelte # High-level markdown → render ($state + $effect)
244-
│ │ ├── MarkdownParsed.svelte # Low-level AST → render component
243+
│ │ ├── MarkdownDocument.svelte # Low-level AST → render component
245244
│ │ ├── MarkdownNode.svelte # Recursive AST node renderer
246-
│ │ ├── Comark*.svelte # Deprecated wrappers for the old component names
247245
│ │ ├── ComarkComponent.svelte # Custom component renderer with named snippets
248246
│ │ └── Resolve.svelte # Stable promise resolver for lazy components
249247
│ ├── async/
250248
│ │ ├── index.ts # Async export (@comark/svelte/async)
251249
│ │ ├── MarkdownAsync.svelte # High-level markdown → render (experimental await)
252-
│ │ ├── ComarkAsync.svelte # Deprecated wrapper for the old component name
253250
│ │ └── ResolveAsync.svelte # Async SSR resolver for lazy components
254251
│ └── plugins/
255252
│ ├── math.ts # Re-exports comark/plugins/math
@@ -315,7 +312,7 @@ Located at `packages/comark-angular/`. Angular 17+ renderer with standalone comp
315312
packages/comark-angular/
316313
├── src/
317314
│ ├── index.ts # Entry point
318-
│ ├── define.ts # defineMarkdownComponent / defineMarkdownParsedComponent
315+
│ ├── define.ts # defineMarkdownComponent / defineMarkdownDocumentComponent
319316
│ ├── components/
320317
│ │ ├── markdown.component.ts # High-level markdown → render component
321318
│ │ ├── markdown-parsed.component.ts # Low-level AST → render component
@@ -348,7 +345,7 @@ packages/comark-angular/
348345
### Usage
349346

350347
```typescript
351-
import { Markdown, MarkdownParsed, defineMarkdownComponent, defineMarkdownParsedComponent } from '@comark/angular'
348+
import { Markdown, MarkdownDocument, defineMarkdownComponent, defineMarkdownDocumentComponent } from '@comark/angular'
352349
import math, { Math } from '@comark/angular/plugins/math'
353350
import mermaid, { Mermaid } from '@comark/angular/plugins/mermaid'
354351
```
@@ -362,22 +359,22 @@ import mermaid, { Mermaid } from '@comark/angular/plugins/mermaid'
362359

363360
```typescript
364361
// Core parsing
365-
import { parse, autoCloseMarkdown } from 'comark'
362+
import { parseMarkdown, autoCloseMarkdown } from 'comark'
366363

367364
// HTML rendering (parse + render in one step)
368-
import { render, renderHTML, createRender } from '@comark/html'
365+
import { createHtmlRenderer, renderHtml, renderHtmlFromDocument } from '@comark/html'
369366

370367
// ANSI terminal rendering
371-
import { log, render, renderANSI, createLog, createRender } from '@comark/ansi'
368+
import { createAnsiRenderer, createAnsiWriter, renderAnsi, renderAnsiFromDocument, writeAnsi } from '@comark/ansi'
372369

373370
// Markdown string rendering (AST → markdown)
374371
import { renderMarkdown } from 'comark/render'
375372

376373
// AST types and utilities
377-
import type { ComarkTree, ComarkNode, ComarkElement, ComarkText } from 'comark'
374+
import type { MarkdownDocument, Node, ElementNode, TextNode } from 'comark'
378375
import { textContent, visit } from 'comark/utils'
379376

380-
// Core plugins — use when calling parse() directly (framework-agnostic)
377+
// Core plugins — use when calling parseMarkdown() directly (framework-agnostic)
381378
import highlight from 'comark/plugins/highlight'
382379
import math from 'comark/plugins/math'
383380
import mermaid from 'comark/plugins/mermaid'
@@ -388,43 +385,39 @@ import alert from 'comark/plugins/alert'
388385
// NOTE: All framework packages re-export every core plugin via their own subpath.
389386
// Prefer the framework-specific path when using a framework renderer:
390387
// @comark/vue/plugins/highlight, @comark/react/plugins/highlight, etc.
391-
// Use comark/plugins/* only when calling parse() without a framework renderer.
388+
// Use comark/plugins/* only when calling parseMarkdown() without a framework renderer.
392389

393390
// HTML rendering — parse + render to HTML string
394-
import { render, renderHTML, createRender } from '@comark/html'
391+
import { createHtmlRenderer, renderHtml, renderHtmlFromDocument } from '@comark/html'
395392
import highlight from '@comark/html/plugins/highlight'
396393
import math, { Math } from '@comark/html/plugins/math'
397394
import mermaid, { Mermaid } from '@comark/html/plugins/mermaid'
398395

399396
// ANSI terminal rendering — parse + render to styled terminal string
400-
import { log, render, renderANSI, createLog, createRender } from '@comark/ansi'
397+
import { createAnsiRenderer, createAnsiWriter, renderAnsi, renderAnsiFromDocument, writeAnsi } from '@comark/ansi'
401398
import highlight from '@comark/ansi/plugins/highlight'
402399
import math from '@comark/ansi/plugins/math'
403400

404401
// Vue — renderer + plugin wrappers (plugin fn + Vue component)
405-
import { Markdown, MarkdownParsed, defineMarkdownComponent } from '@comark/vue'
402+
import { Markdown, MarkdownDocument, defineMarkdownComponent } from '@comark/vue'
406403
import math, { Math } from '@comark/vue/plugins/math'
407404
import mermaid, { Mermaid } from '@comark/vue/plugins/mermaid'
408405

409406
// React — renderer + plugin wrappers (plugin fn + React component)
410-
import { Markdown, MarkdownParsed, defineMarkdownComponent } from '@comark/react'
407+
import { Markdown, MarkdownDocument, defineMarkdownComponent } from '@comark/react'
411408
import math, { Math } from '@comark/react/plugins/math'
412409
import mermaid, { Mermaid } from '@comark/react/plugins/mermaid'
413410

414411
// Svelte — renderer + plugin wrappers (plugin fn + Svelte component)
415-
import { Markdown, MarkdownParsed } from '@comark/svelte'
412+
import { Markdown, MarkdownDocument } from '@comark/svelte'
416413
import { MarkdownAsync } from '@comark/svelte/async' // requires experimental.async
417414
import math, { Math } from '@comark/svelte/plugins/math'
418415
import mermaid, { Mermaid } from '@comark/svelte/plugins/mermaid'
419416

420417
// Angular — renderer + plugin wrappers (plugin fn + Angular component)
421-
import { Markdown, MarkdownParsed, defineMarkdownComponent, defineMarkdownParsedComponent } from '@comark/angular'
418+
import { Markdown, MarkdownDocument, defineMarkdownComponent, defineMarkdownDocumentComponent } from '@comark/angular'
422419
import math, { Math } from '@comark/angular/plugins/math'
423420
import mermaid, { Mermaid } from '@comark/angular/plugins/mermaid'
424-
425-
// NOTE: The old component names (Comark, ComarkRenderer, ComarkAsync,
426-
// defineComarkComponent, defineComarkRendererComponent, ...) remain
427-
// exported as deprecated aliases.
428421
```
429422

430423
## Coding Principles
@@ -482,16 +475,16 @@ describe('functionUnderTest', () => {
482475

483476
## Key APIs
484477

485-
### parse(source, options)
478+
### parseMarkdown(source, options)
486479

487480
```typescript
488-
const result = await parse(markdownContent, {
481+
const result = await parseMarkdown(markdownContent, {
489482
autoUnwrap: true, // Remove <p> wrappers from single-paragraph containers
490483
autoClose: true, // Auto-close incomplete syntax
491484
unwrap: 'p', // Strip top-level wrapper tags (MDC unwrap); merges paragraphs
492485
})
493486

494-
result.nodes // ComarkNode[]
487+
result.nodes // Node[]
495488
result.frontmatter // Record<string, any>
496489
result.meta // Record<string, any>
497490
```
@@ -503,14 +496,16 @@ autoCloseMarkdown('**bold text') // '**bold text**'
503496
autoCloseMarkdown('::alert\nContent') // '::alert\nContent\n::'
504497
```
505498

506-
## Comark AST Format
499+
## Markdown Document Model
507500

508501
```typescript
509-
type ComarkText = string
510-
type ComarkElement = [string, ComarkElementAttributes, ...ComarkNode[]]
511-
type ComarkNode = ComarkElement | ComarkText
512-
type ComarkTree = {
513-
nodes: ComarkNode[]
502+
type TextNode = string
503+
type ElementNodeAttributes = { [key: string]: unknown; $?: { line?: number; html?: 0 | 1; block?: 0 | 1 } }
504+
type ElementNode = [string, ElementNodeAttributes, ...Node[]]
505+
type CommentNode = [null, ElementNodeAttributes, string]
506+
type Node = ElementNode | TextNode | CommentNode
507+
type MarkdownDocument = {
508+
nodes: Node[]
514509
frontmatter: Record<string, any>
515510
meta: Record<string, any>
516511
}

benchmarks/comark-parse.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { bench, run, barplot, group } from 'mitata'
22
import MarkdownIt from 'markdown-it'
33
import MarkdownExit from 'markdown-exit'
44
import { markdownItComark } from 'comark/plugins/syntax'
5-
import { createParse } from 'comark'
5+
import { createMarkdownParser } from 'comark'
66

77
// Sample markdown content to test with
88
const sampleMarkdown = `---
@@ -71,9 +71,9 @@ const markdownExit = new MarkdownExit({
7171
.enable(['table', 'strikethrough'])
7272
.use(markdownItComark)
7373

74-
const comark = createParse()
75-
const comarkNoClose = createParse({ autoClose: false })
76-
const comarkStreaming = createParse()
74+
const comark = createMarkdownParser()
75+
const comarkNoClose = createMarkdownParser({ autoClose: false })
76+
const comarkStreaming = createMarkdownParser()
7777

7878
barplot(() => {
7979
group('parse', () => {

benchmarks/comark-render.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { bench, run, barplot, group } from 'mitata'
22
import MarkdownIt from 'markdown-it'
33
import MarkdownExit from 'markdown-exit'
44
import { markdownItComark } from 'comark/plugins/syntax'
5-
import { createParse } from 'comark'
6-
import { renderHTML } from '../packages/comark-html/src/index.ts'
5+
import { createMarkdownParser } from 'comark'
6+
import { renderHtmlFromDocument } from '../packages/comark-html/src/index.ts'
77

88
// Sample markdown content to test with
99
const sampleMarkdown = `---
@@ -72,9 +72,9 @@ const markdownExit = new MarkdownExit({
7272
.enable(['table', 'strikethrough'])
7373
.use(markdownItComark)
7474

75-
const comark = createParse()
76-
const comarkNoClose = createParse({ autoClose: false })
77-
const comarkStreaming = createParse()
75+
const comark = createMarkdownParser()
76+
const comarkNoClose = createMarkdownParser({ autoClose: false })
77+
const comarkStreaming = createMarkdownParser()
7878

7979
barplot(() => {
8080
group('render', () => {
@@ -88,20 +88,20 @@ barplot(() => {
8888
markdownExit.render(sampleMarkdown)
8989
})
9090

91-
// Benchmark: comark parse + renderHTML
92-
bench('comark parse + renderHTML', async () => {
93-
const tree = await comark(sampleMarkdown)
94-
renderHTML(tree)
91+
// Benchmark: comark parse + renderHtmlFromDocument
92+
bench('comark parse + renderHtmlFromDocument', async () => {
93+
const doc = await comark(sampleMarkdown)
94+
renderHtmlFromDocument(doc)
9595
})
9696

9797
bench('comark parse no close', async () => {
98-
const tree = await comarkNoClose(sampleMarkdown)
99-
renderHTML(tree)
98+
const doc = await comarkNoClose(sampleMarkdown)
99+
renderHtmlFromDocument(doc)
100100
})
101101

102102
bench('comark parse streaming', async () => {
103-
const tree = await comarkStreaming(sampleMarkdown, { streaming: true })
104-
renderHTML(tree)
103+
const doc = await comarkStreaming(sampleMarkdown, { streaming: true })
104+
renderHtmlFromDocument(doc)
105105
})
106106
})
107107
})

benchmarks/plugin-highlight.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { bench, run, group, barplot } from 'mitata'
22
import MarkdownIt from 'markdown-it'
33
import MarkdownExit from 'markdown-exit'
44
import { markdownItComark } from 'comark/plugins/syntax'
5-
import { createParse } from 'comark'
5+
import { createMarkdownParser } from 'comark'
66
import highlight, { getHighlighter } from '../packages/comark/src/plugins/highlight'
77
import { codeToHast } from 'shiki/core'
88

@@ -18,8 +18,8 @@ npm install comark
1818
Then use it:
1919
2020
\`\`\`javascript
21-
import { parse } from 'comark'
22-
const tree = await parse('# Hello')
21+
import { parseMarkdown } from 'comark'
22+
const tree = await parseMarkdown('# Hello')
2323
\`\`\`
2424
`
2525

@@ -29,15 +29,15 @@ const medium = `
2929
## Parse
3030
3131
\`\`\`typescript
32-
import { parse } from 'comark'
32+
import { parseMarkdown } from 'comark'
3333
34-
interface ParseOptions {
34+
interface ParserOptions {
3535
autoClose?: boolean
3636
streaming?: boolean
3737
plugins?: ComarkPlugin[]
3838
}
3939
40-
const tree = await parse(markdown, {
40+
const tree = await parseMarkdown(markdown, {
4141
autoClose: true,
4242
plugins: [highlight()],
4343
})
@@ -99,8 +99,8 @@ const markdownExit = new MarkdownExit({ html: true, linkify: true })
9999
.use(markdownItComark)
100100

101101
// comark: baseline vs highlight plugin
102-
const comark = createParse()
103-
const comarkHl = createParse({ plugins: [highlight()] })
102+
const comark = createMarkdownParser()
103+
const comarkHl = createMarkdownParser({ plugins: [highlight()] })
104104

105105
// Pre-warm shiki so we benchmark steady-state, not cold-start
106106
const shiki = await getHighlighter()

0 commit comments

Comments
 (0)