Skip to content

API Reference

Blazingly fast Markdown parser.

Options

Bases: IntFlag

IntFlag containing flags for enabling pulldown_cmark options.

Examples:

options = (
    pyromark.Options.ENABLE_TABLES
    | pyromark.Options.ENABLE_MATH
    | pyromark.Options.ENABLE_GFM
)

ENABLE_TABLES class-attribute instance-attribute

ENABLE_TABLES = 1 << 1

ENABLE_FOOTNOTES class-attribute instance-attribute

ENABLE_FOOTNOTES = 1 << 2

ENABLE_STRIKETHROUGH class-attribute instance-attribute

ENABLE_STRIKETHROUGH = 1 << 3

ENABLE_TASKLISTS class-attribute instance-attribute

ENABLE_TASKLISTS = 1 << 4

ENABLE_SMART_PUNCTUATION class-attribute instance-attribute

ENABLE_SMART_PUNCTUATION = 1 << 5

ENABLE_HEADING_ATTRIBUTES class-attribute instance-attribute

ENABLE_HEADING_ATTRIBUTES = 1 << 6

ENABLE_YAML_STYLE_METADATA_BLOCKS class-attribute instance-attribute

ENABLE_YAML_STYLE_METADATA_BLOCKS = 1 << 7

ENABLE_PLUSES_DELIMITED_METADATA_BLOCKS class-attribute instance-attribute

ENABLE_PLUSES_DELIMITED_METADATA_BLOCKS = 1 << 8

ENABLE_OLD_FOOTNOTES class-attribute instance-attribute

ENABLE_OLD_FOOTNOTES = 1 << 9 | 1 << 2

ENABLE_MATH class-attribute instance-attribute

ENABLE_MATH = 1 << 10

ENABLE_GFM class-attribute instance-attribute

ENABLE_GFM = 1 << 11

ENABLE_DEFINITION_LIST class-attribute instance-attribute

ENABLE_DEFINITION_LIST = 1 << 12

ENABLE_SUPERSCRIPT class-attribute instance-attribute

ENABLE_SUPERSCRIPT = 1 << 13

ENABLE_SUBSCRIPT class-attribute instance-attribute

ENABLE_SUBSCRIPT = 1 << 14
ENABLE_WIKILINKS = 1 << 15

Markdown

Markdown(*, options: Options = Options(0))

events method descriptor

events(
    markdown: str, /, *, merge_text: bool = True
) -> tuple[Event, ...]

Examples:

for event in md.events(
    "# Hello world",
    options=(
        pyromark.Options.ENABLE_TABLES
        | pyromark.Options.ENABLE_MATH
        | pyromark.Options.ENABLE_GFM
    )
):
    # All event types are fully type annotated
    # so you will get static type checking
    # and Tab completions in your IDE!
    match event:
        case {"Start": {"Heading": {"level": heading_level}}}:
            print(f"Heading with {heading_level} level started")
        case {"Text": text}:
            print(f"Got {text!r} text")
        case {"End": {"Heading": heading_level}}:
            print(f"Heading with {heading_level} level ended")
        case other_event:
            print(f"Got {other_event!r}")

events_with_range method descriptor

events_with_range(
    markdown: str,
) -> tuple[tuple[Event, Range], ...]

Examples:

for event, range_ in md.events_with_range(
    "# Hello world",
    options=(
        pyromark.Options.ENABLE_TABLES
        | pyromark.Options.ENABLE_MATH
        | pyromark.Options.ENABLE_GFM
    )
):
    # All event types are fully type annotated
    # so you will get static type checking
    # and Tab completions in your IDE!
    match event:
        case {"Start": {"Heading": {"level": heading_level}}}:
            print(
                f"Heading with {heading_level} level started, "
                f"{range_=}"
            )
        case {"Text": text}:
            print(f"Got {text!r} text, {range_=}")
        case {"End": {"Heading": heading_level}}:
            print(
                f"Heading with {heading_level} level ended, "
                f"{range_=}"
            )
        case other_event:
            print(f"Got {other_event!r}, {range_=}")

html method descriptor

html(markdown: str) -> str

Examples:

html = md.html("# Hello world")
assert html == "<h1>Hello world</h1>\n"

events builtin

events(
    markdown: str,
    /,
    *,
    options: Options = 0,
    merge_text: bool = True,
) -> tuple[Event, ...]

Examples:

for event in pyromark.events(
    "# Hello world",
    options=(
        pyromark.Options.ENABLE_TABLES
        | pyromark.Options.ENABLE_MATH
        | pyromark.Options.ENABLE_GFM
    )
):
    # All event types are fully type annotated
    # so you will get static type checking
    # and Tab completions in your IDE!
    match event:
        case {"Start": {"Heading": {"level": heading_level}}}:
            print(f"Heading with {heading_level} level started")
        case {"Text": text}:
            print(f"Got {text!r} text")
        case {"End": {"Heading": heading_level}}:
            print(f"Heading with {heading_level} level ended")
        case other_event:
            print(f"Got {other_event!r}")

events_with_range builtin

events_with_range(
    markdown: str, /, *, options: Options = 0
) -> tuple[tuple[Event, Range], ...]

Examples:

for event, range_ in pyromark.events_with_range(
    "# Hello world",
    options=(
        pyromark.Options.ENABLE_TABLES
        | pyromark.Options.ENABLE_MATH
        | pyromark.Options.ENABLE_GFM
    )
):
    # All event types are fully type annotated
    # so you will get static type checking
    # and Tab completions in your IDE!
    match event:
        case {"Start": {"Heading": {"level": heading_level}}}:
            print(
                f"Heading with {heading_level} level started, {range_=}"
            )
        case {"Text": text}:
            print(f"Got {text!r} text, {range_=}")
        case {"End": {"Heading": heading_level}}:
            print(
                f"Heading with {heading_level} level ended, {range_=}"
            )
        case other_event:
            print(f"Got {other_event!r}, {range_=}")

html builtin

html(markdown: str, /, *, options: Options = 0) -> str

Examples:

html = pyromark.html(
    "# Hello world",
    options=(
        pyromark.Options.ENABLE_TABLES
        | pyromark.Options.ENABLE_MATH
        | pyromark.Options.ENABLE_GFM
    )
)
assert html == "<h1>Hello world</h1>\n"

event

Event module-attribute

Event: TypeAlias = (
    _Start
    | _End
    | _Text
    | _Code
    | _InlineMath
    | _DisplayMath
    | _Html
    | _InlineHtml
    | _FootnoteReference
    | Literal["SoftBreak"]
    | Literal["HardBreak"]
    | Literal["Rule"]
    | _TaskListMarker
)

Range

Bases: TypedDict

start instance-attribute

start: int

end instance-attribute

end: int