parse()

Parse a Markdown string and return the root AST node.

Usage

Source

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

This is the primary entry point for AST-based document inspection and transformation. The returned Node provides tree traversal, property access, mutation, and rendering methods.

Parameters

text: str

The Markdown string to parse.

hardbreaks: bool = False

Render soft 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] = ()

GFM extensions to enable.

options: int = 0
Raw Options bitmask.

Returns

Node
The root document node. Its ~Node.type() is NodeType.DOCUMENT.

Examples

from multimark import parse, NodeType

doc = parse("# Hello\n\nWorld!\n")
for event, node in doc.walk():
    if event == "enter" and node.type == NodeType.HEADING:
        print(f"Found heading level {node.heading_level}")