Streaming markdown parser and renderer with support for CommonMark, GFM extensions (tables, strikethrough, autolinks, task lists), and djot features (fenced divs, inline attributes). Provides static terminal rendering via TSS, streaming terminal rendering for LLM output, and HTML5 output.
| Module | Description |
|---|---|
| markdown.buffer | Streaming buffer for chunk boundary handling in inline parsing. |
| markdown.events | Callback-based event emitter for the markdown parser. |
| markdown.inline | Inline element parser using a two-phase opener stack approach. |
| markdown.parser | Core streaming parser that coordinates block detection, inline parsing, and callback-based event emission. |
| markdown.renderer | Renderer registry and factory with three implementations: static (full document rendering for pager display), streaming (live cursor-based rendering for LLM output), and html (semantic HTML5). |
| markdown.state | Block state machine with pattern-based detection for CommonMark block structures: headings, code fences, thematic breaks, lists, tables, blockquotes, divs, link references, and footnotes. |
| Name | Signature |
|---|---|
stream | stream(options) -> parser |
render | render(input, options) -> result, err |
render_html | render_html(input, options) -> html, err |
parse | parse(input, options) -> events |
stream(
options) ->parser
Create a streaming parser instance for incremental parsing
Returns a parser instance with feed(chunk), finish(), reset(), and
set_event_callback(fn) methods. Options:
on_event: callback function(event) invoked for each parser event
inline: parse inline elements (default true)
streaming_inline: emit inline events incrementally (default true)
render(
input,options) ->result,err
Render markdown to styled terminal output
Parses and renders markdown through the named renderer. Options:
renderer: renderer name ("static" default)
width: content width (default 80)
rss: custom RSS table to merge with defaults
indent: global indentation (default 0)
hide_link_urls: hide URLs in rendered output (default false)
supports_ts: terminal supports OSC 66 text sizing (default true)
render_html(
input,options) ->html,err
Render markdown to semantic HTML5
parse(
input,options) ->events
Parse markdown and collect events into an array
Parses input and returns an array of event tables. Options:
on_event: custom callback (default: collect into array)
inline: parse inline elements (default true)
streaming_inline: emit inline events incrementally (default true)