@@ -46,13 +46,13 @@ Located at `packages/comark/`:
4646```
4747packages/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'
103103import highlight from ' @comark/html/plugins/highlight'
104104import 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'
139139import highlight from ' @comark/ansi/plugins/highlight'
140140import 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'
189189import math , { Math } from ' @comark/vue/plugins/math'
190190import 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'
229228import math , { Math } from ' @comark/react/plugins/math'
230229import 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
315312packages/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'
352349import math , { Math } from ' @comark/angular/plugins/math'
353350import 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)
374371import { 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'
378375import { 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)
381378import highlight from ' comark/plugins/highlight'
382379import math from ' comark/plugins/math'
383380import 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'
395392import highlight from ' @comark/html/plugins/highlight'
396393import math , { Math } from ' @comark/html/plugins/math'
397394import 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'
401398import highlight from ' @comark/ansi/plugins/highlight'
402399import 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'
406403import math , { Math } from ' @comark/vue/plugins/math'
407404import 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'
411408import math , { Math } from ' @comark/react/plugins/math'
412409import 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'
416413import { MarkdownAsync } from ' @comark/svelte/async' // requires experimental.async
417414import math , { Math } from ' @comark/svelte/plugins/math'
418415import 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'
422419import math , { Math } from ' @comark/angular/plugins/math'
423420import 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 []
495488result .frontmatter // Record<string, any>
496489result .meta // Record<string, any>
497490```
@@ -503,14 +496,16 @@ autoCloseMarkdown('**bold text') // '**bold text**'
503496autoCloseMarkdown (' ::alert\n Content' ) // '::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}
0 commit comments