Skip to content
Projets

À propos

Blazingly fast CommonMark-compliant Markdown pull parser for Python, written in Rust. Renders HTML, yields typed parser events, supports GFM extensions and syntax highlighting.

Développement web et applicatif

Comment ces chiffres sont mesurés

Progression mesurée des étoiles

in 24h
+1
in 7 days
+1
in 15 days
+1
in 1 month
Historique en cours

Variations nettes sur des périodes qui se chevauchent, pas des totaux quotidiens. Les mesures absentes restent vides. Les étoiles indiquent l’intérêt, pas la qualité.

README.md

Original

pyromark

Downloads

pyromark (stands for Python Rust Optimized Markdown) is a blazingly fast CommonMark-compliant Markdown pull parser for Python, built on the pulldown-cmark Rust crate.

Installation

uv add pyromark
# or
pip install -U pyromark

Documentation

https://monosans.github.io/pyromark

Examples

Convert Markdown to HTML

import pyromark

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

The output is not sanitized, so sanitize it before serving Markdown you did not write.

Iterate over Markdown elements

import pyromark

for event in pyromark.events("# Hello world"):
    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 are fully type annotated, so your editor knows the shape of each one.

Enable extensions and highlight code

import pyromark

html = pyromark.html(
    "| a | b |\n| - | - |\n| 1 | 2 |",
    options=pyromark.Options.ENABLE_TABLES,
    highlight=pyromark.Theme.INSPIRED_GITHUB,
)

Command line

pyromark README.md --enable-tables --highlight inspired-github -o out.html

Performance

2.6x faster than cmarkgfm (C) and comrak (Rust). 86x to 367x faster than pure Python parsers: mistune, markdown-it-py, Markdown, mistletoe, markdown2 and marko.

html and write_html release the GIL, so threads render in parallel.

See benchmark.

License

MIT

Explorer des projets similaires

Chargement…