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.from_html | HTML → markdown content extraction. |
| 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. |
| markdown.tightness | Event filter that resolves CommonMark list tightness exactly. |
| Name | Signature |
|---|---|
| stream | stream(options) -> parser |
| render | render(input, options) -> result, err |
| render_html | render_html(input, options) -> html, err |
| from_html | from_html(html) -> markdown |
| 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 eventinline: parse inline elements (default true)streaming_inline: emit inline events incrementally (default true)List tightness cannot be known when a list starts, so tight on a list's
block_start is provisional. The parser emits a list_loose event for the
innermost open list the moment a blank line proves it loose. Consumers that
can afford to buffer should wrap on_event in markdown.tightness to get
the resolved value on block_start instead.
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 defaultsindent: global indentation (default 0)hide_link_urls: hide URLs in rendered output (default false)supports_ts: terminal supports OSC 66 text sizing (default true)cell_w, cell_h: terminal cell size in pixels; caps image display
width at natural size and refines image row estimatesrender_html(
input,options) ->html,err
Render markdown to semantic HTML5
from_html(
html) ->markdown
Extract a markdown-friendly rendering from raw HTML
Picks the article root from messy real-world HTML, strips noise tags,
converts structural tags to markdown, and decodes entities. Output is
intended for a markdown renderer or pager — see markdown.from_html
submodule for decode_entities if needed separately.
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)resolve_tightness: resolve list looseness onto each list's block_start
instead of reporting it through list_loose events (default false)