Skip to main content

Parser

Streaming CommonMark/GFM parser.

Usage

Source

Parser(
    *,
    hardbreaks=False,
    smart=False,
    normalize=False,
    unsafe=False,
    footnotes=False,
    extensions=(),
    options=0,
)

Wraps the cmark-gfm streaming parser, allowing incremental feeding of Markdown content and rendering to any output format. Useful for processing large documents or streaming input without buffering the entire source in memory.

Parameters

hardbreaks: bool = False

Render soft line breaks as hard breaks. Default False.

smart: bool = False

Enable smart punctuation. Default False.

normalize: bool = False

Consolidate adjacent text nodes. Default False.

unsafe: bool = False

Allow raw HTML passthrough. Default False.

footnotes: bool = False

Enable footnote syntax. Default False.

extensions: Sequence[str] = ()

Extensions to enable (e.g., ["table", "strikethrough", "math"]).

options: int = 0
Raw Options bitmask, OR’d with boolean kwargs.

Examples

Basic streaming usage:

from multimark import Parser

parser = Parser(smart=True)
parser.feed("# Hello\n\n")
parser.feed("World!\n")
html = parser.render_html()

Context manager:

with Parser(extensions=["table"]) as p:
    p.feed("| A | B |\n|---|---|\n| 1 | 2 |\n")
    html = p.render_html()

Functions

Name Description
close() Release all C resources held by this parser.
feed() Feed a chunk of Markdown text to the parser.
finish() Finalize parsing and return the root Node of the AST.
render_commonmark() Finish parsing (if needed) and render as normalized CommonMark.
render_html() Finish parsing (if needed) and render as HTML.
render_latex() Finish parsing (if needed) and render as LaTeX.
render_man() Finish parsing (if needed) and render as a groff man page.
render_plaintext() Finish parsing (if needed) and render as readable plain text.
render_xml() Finish parsing (if needed) and render as XML.