Skip to main content

Mordant

CI License PyPI - Version Python crates.io Rust

Version: 0.11.0 (Python and Rust crates in lockstep) Python: 3.11+ · Bindings: PyO3 0.29

A fast CommonMark + GFM Markdown parser and renderer for Python, powered by the mordant Rust library — itself built on the rushdown engine by Yusuke Inuzuka.

Features

  • Blazing fast — one of the fastest Markdown parsers for Python; up to 55x faster than python-markdown on large documents
  • CommonMark 0.31.2 + GFM — tables, task lists, strikethrough; autolink available via GfmOptions.all()
  • Full AST access — parse() returns a Document; traverse parents, children and siblings; kind-specific properties on every node
  • YAML frontmatter — typed metadata extraction (null, bool, int, float, str, list, dict)
  • Emoji shortcodes — :joy: → 😂 with blacklists and custom templates
  • LaTeX math — KaTeX 0.18.5: fenced ```math/```latex blocks, inline $…$ and $$…$$, standalone render_math(); KATEX_VERSION reports the bundled CSS version
  • Mermaid diagrams — server-side inline SVG by default (~3ms), legacy client-side Mermaid.js mode, hybrid fallback; themeable from code-highlighting themes
  • Footnotes — PHP Markdown Extra style [^1] with backlinks
  • Definition lists, fenced divs, link attributes — Term + : definition, Pandoc-style ::: divs, and {#id .class} after links/images; unsafe attributes need allows_unsafe=True and URL checks normalize entities/whitespace
  • Runtime engine switches — all engines ship in the wheel; disable any of them with mordant.Engines
  • Lint engine — 25 markdownlint-style rules, auto-fix engine, inline suppressions, .markdownlint.json config support
  • Batch linting — lint_many() / fix_many() process many files in parallel via rayon
  • CLI — python -m mordant with --fix, --dry-run, --format human|json|github, glob/directory recursion
  • Document chunking — MarkdownChunker: lazy, low-copy chunk iterator with heading context, built for RAG/embedding pipelines
  • Syntax highlighting — 190+ languages via syntect-assets (bat's syntaxes), VSCode JSON and Sublime .tmTheme themes
  • Multi-threaded — parse, render, lint and fix release the GIL; scales ~4x linearly with thread count

Install

pip install mordant

Or build from source (requires a Rust toolchain):

git clone https://github.com/opticsWolf/mordant
cd mordant/mordant-py
pip install -e .

Rust users can use the same engine directly: cargo add mordant.

Quick Start

import mordant

html = mordant.markdown_to_html("# Hello\n\n**World**")
# '<h1>Hello</h1>\n<p><strong>World</strong></p>\n'

GFM options

opts = mordant.GfmOptions(features=[
    mordant.GfmFeature.Table,
    mordant.GfmFeature.Strikethrough,
    mordant.GfmFeature.TaskList,
])
html = mordant.markdown_to_html("~~strike~~", gfm_opts=opts)

opts = mordant.GfmOptions.all()   # everything incl. the linkify extension
opts = mordant.GfmOptions.none()

Engine switches

Every engine is bundled and enabled by default except syntax highlighting (use mordant.Engines.all() to enable it):

html = mordant.markdown_to_html(":smile:", engines=mordant.Engines.none())
html = mordant.markdown_to_html(
    "Apple\n: A fruit.\n",
    engines=mordant.Engines.only(["definition_list"]),
)

# Structured renderer options
opts = mordant.RenderOptions(
    engines=mordant.Engines.all(),
    math=mordant.MathRendererOptions(output="mathml"),
    highlighter=mordant.HighlighterOptions(theme="Dracula", mode="Class"),
)
html = mordant.markdown_to_html("```math\nx^2\n```", render_opts=opts)

Parse to an AST

doc = mordant.parse("# Hello\n\nSome **bold** text.")

doc.kind        # "Document"
doc.children    # [Heading, Paragraph]

for node in doc.walk("depth"):
    print(node.kind, node.text)

heading = doc.children[0]
heading.content          # rendered inner HTML
heading.level            # kind-specific property (1)

# YAML frontmatter (if present at the top of the document)
print(doc.metadata)      # {'title': 'My Document', 'tags': ['a', 'b']}

Frontmatter is controlled through ParseOptions, e.g. ParseOptions(meta_table=True) also injects it as a table.

Emoji

html = mordant.markdown_to_html("I love :heart: and :joy:")
# 'I love ❤️ and 😂'

# Ignore specific shortcodes
html = mordant.markdown_to_html(
    ":joy: stays literal",
    emoji_parse_opts=mordant.EmojiParserOptions(blacklist="joy"),
)

# Custom render template ({emoji}, {shortcode}, {name})
html = mordant.markdown_to_html(
    ":joy:",
    emoji_render_opts=mordant.EmojiHtmlRendererOptions(
        template='<img src="https://cdn.example.com/{shortcode}.png" />'
    ),
)

Math (KaTeX)

```math / ```latex fences and inline $…$ / $$…$$ are rendered automatically. Include mordant.KATEX_CSS in your page for styling; mordant.KATEX_VERSION is "0.18.5" (matching katex-rs 0.3.0).

html = mordant.markdown_to_html("Euler: $e^{i\\pi} + 1 = 0$")

# Standalone rendering, independent of any document
markup = mordant.render_math("E = mc^2", display=True, output="both")

Mermaid diagrams

```mermaid blocks render as inline SVG server-side by default — no CDN or JavaScript needed:

html = mordant.markdown_to_html("""```mermaid
graph LR
    A --> B --> C
```""")
# '<div class="mermaid"><svg>...</svg></div>'

# Legacy client-side rendering, or server→client fallback
opts = mordant.DiagramHtmlRendererOptions(render_mode="client")
opts = mordant.DiagramHtmlRendererOptions(render_mode="hybrid")

# One theme for BOTH code highlighting and diagrams
html = mordant.markdown_to_html(src, theme="Dracula")

Linting & fixing

diagnostics = mordant.lint("# Hello\n\n### Jump\n")
for d in diagnostics:
    print(f"{d.rule}:{d.line} {d.name}: {d.message}")
# MD001:1 heading-increment: Heading incremented by more than 1

result = mordant.fix("trailing   \n\n\ntext")
result.output      # 'trailing\n\ntext\n'
result.fixed       # what was auto-corrected
result.unfixable   # what needs manual attention

# Rule catalogue
for meta in mordant.lint_rules():
    print(meta.id, meta.name, meta.fixable)

Batch process a whole tree (parallel, GIL released):

results = mordant.lint_many(["a.md", "b.md", "notes/*.md"])

Or from the command line:

python -m mordant check docs/*.md --format github
python -m mordant check docs/ --fix

Inline suppressions work too: <!-- markdownlint-disable MD013 -->.

Document chunking

Built for RAG/embedding pipelines — a lazy, low-copy chunk iterator with heading-context tracking:

chunker = mordant.MarkdownChunker(text)          # or .from_file(path)
# or zero-copy: MarkdownChunker.from_file_mmap(path)

for chunk in chunker:                             # bare str chunks
    embed(chunk)

chunks = chunker.get_chunks_with_context()        # ExtractedChunk objects:
chunks[0].text                                    # "# Title\n\nbody…" (context-prefixed)
chunks[0].block_type                              # "Paragraph", "CodeBlock", …
chunks[0].start_offset, chunks[0].end_offset      # byte offsets in source

# Overlap payloads for embedding models
payloads = chunker.compute_overlap_payloads(overlap_words=50)

Syntax highlighting

hl = mordant.Highlighter(theme="Dracula", mode="Attribute")
html = hl.highlight("python", "def hello():\n    print('hi')")

# In documents
html = mordant.markdown_to_html(src,
    highlighting_theme="Dracula",
    highlighting_mode="Attribute")     # or "Class" for CSS classes

# Custom themes: VSCode JSON or Sublime .tmTheme
mordant.add_custom_theme("my-theme", open("theme.json").read())
mordant.list_themes()
mordant.list_syntaxes()                # ~190 languages

Multi-threading

CPU-heavy work (parse, render, lint, fix, batch operations) runs without the GIL, so plain threading scales across cores:

from concurrent.futures import ThreadPoolExecutor
import mordant

with ThreadPoolExecutor(8) as pool:
    htmls = list(pool.map(mordant.markdown_to_html, documents))

Documentation

  • Quick Reference — complete API reference with every option
  • Architecture — internals, design decisions, module map
  • README — project overview, Rust crate feature table

License

MIT

Metadata

Release files for mordant 0.11.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mordant 0.11.0
File Size Uploaded Provenance Actions
mordant-0.11.0.tar.gz 834.3 kB With provenance Details for mordant-0.11.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for mordant 0.11.0
File Interpreter ABI Platform Actions
mordant-0.11.0-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details for mordant-0.11.0-cp311-abi3-win_amd64.whl
mordant-0.11.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.11 abi3 Linux glibc 2.17+ x86-64 Details for mordant-0.11.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
mordant-0.11.0-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details for mordant-0.11.0-cp311-abi3-macosx_11_0_arm64.whl

Total release size: 16.1 MB

Release files / mordant-0.11.0.tar.gz

Download URL mordant-0.11.0.tar.gz
Size 834.3 kB
Tags Source
SHA-256 checksum
How to use checksums
f594011f562c637ecbd970bcec54d2252808341ead781fcd806d888be69e4ab1
BLAKE2b-256 checksum
How to use checksums
f0c41c4a7163deec988e2189346a5a058f3222237a31c99b13750e8b7812d0bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Release files / mordant-0.11.0-cp311-abi3-win_amd64.whl

Download URL mordant-0.11.0-cp311-abi3-win_amd64.whl
Size 5.0 MB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
a010652ec23fb96c6a39e9513fad7cf8b49b77b0cd91cfe4d9682095672d37f7
BLAKE2b-256 checksum
How to use checksums
88eb9d11e8ed955619093de7fbaed1aeb11d3a8f0158eb28375ebb7b91f631d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Release files / mordant-0.11.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL mordant-0.11.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 5.4 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
685433f0f554cee11a9ef6981aeaf5693c6974add367462440fd35628cb3dd7e
BLAKE2b-256 checksum
How to use checksums
33deb9c1fc4f1bee807f8bf2081e8ca84810c7b9f9caeb6693ca28a232b0ec0c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Release files / mordant-0.11.0-cp311-abi3-macosx_11_0_arm64.whl

Download URL mordant-0.11.0-cp311-abi3-macosx_11_0_arm64.whl
Size 4.9 MB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
71e1d3a972dac2147932efd612080263a7e291f6a3f0620b7c8960aa87b6ec64
BLAKE2b-256 checksum
How to use checksums
aee6476007e71f7dd11bdc27c7732297c86807320f6dd4263dddc5f293771d26
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Security for mordant 0.11.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 4 files in this release have been uploaded with provenance metadata.

Select from 4 files

Attestation for mordant-0.11.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page