Skip to main content

illusion-markdown

PyPI Python License

Official Python bindings for illusion Markdown (MDI). illusion-markdown parses complete MDI documents, returns the versioned document IR, and renders HTML, text, EPUB, and DOCX through the canonical Rust implementation. Python is an ergonomic API layer only: it does not carry a second Markdown parser or renderer.

Read the Python API documentation →

Install

pip install illusion-markdown

The PyPI distribution is illusion-markdown; the Python import namespace is mdi. Python 3.10 or newer is required.

Quick start

import mdi

source = """---
title: 東京の夜
lang: ja
---

# {東京|とうきょう}の夜

第^12^話
"""

result = mdi.parse(source)
print(result["document"]["children"][0]["type"])

html = mdi.render_html(source)
open("book.html", "w", encoding="utf-8").write(html)

parse() returns a JSON-compatible dictionary with the MDI syntax version, IR version, parser capabilities, document tree, and recoverable diagnostics. Every source-backed span is a half-open UTF-8 byte range.

API

Function Result
mdi.parse(source) Versioned document IR and diagnostics.
mdi.serialize_mdi(source) Canonical MDI/Markdown source.
mdi.render_html(source) A standalone HTML document.
mdi.render_text(source) Deterministic plain text.
mdi.render_text_format(source, format) TXT, ruby, Narou, Kakuyomu, Aozora, or note text.
mdi.render_epub(source) EPUB 3 archive bytes.
mdi.render_docx(source) DOCX archive bytes.
epub_bytes = mdi.render_epub("# Chapter\n\nText")
with open("book.epub", "wb") as output:
    output.write(epub_bytes)

See the official Python documentation for API details, the complete MDI syntax, output formats, and architecture.

Platform support

Prebuilt wheels are published for macOS (Intel and Apple Silicon), Linux x64, and Windows x64. A source distribution is also available for other platforms with a supported Rust toolchain.

Development

The binding is tested against a locally built native extension. From this directory, use Python 3.10 or newer:

python -m pip install -e ".[test]"
python -m pytest --cov=mdi --cov-branch

The test suite covers the public Python contract, including the versioned IR, UTF-8 byte spans, diagnostics, all text exports, archive structure, type boundaries, and the stable API surface.

License

MIT

Automatic warichu presentation layout

The Rust core supplies two lines at 50% body size with no line gap. Capacity is measured in half-em units at the note font size; it is a character-width estimate, not exact proportional-font measurement. The first fragment can use the space remaining on the current body line; following fragments use the full capacity.

from mdi import layout_warichu
fragments = layout_warichu([{"type": "text", "value": "一二三四五六"}], 4, first_capacity=2)

Results contain lines, html, widths, overflow, hardBreakAfter, and sources. Each source has a child-index path relative to the input inline array, half-open startUtf8 / endUtf8 offsets into that leaf's visible text, and an indivisible group ID. A cluster crossing formatting boundaries shares a group. Ruby, tcy, no-break and unknown containers remain whole; their coordinates use projected visible text (ruby base, excluding its reading). Oversized groups remain available and report overflow. Author hard breaks are retained; automatic splits never enter canonical MDI or plain text.

The C ABI provides mdi_layout_warichu_json, taking inline-array JSON and options JSON (firstCapacity, continuationCapacity) and returning the same JSON through mdi_ffi_result. Release both returned buffers with mdi_free_buffer. Static HTML/EPUB includes readable precomputed lines; reader reflow can differ. DOCX uses native Word combination groups; XML verification is not a Word rendering test. Custom sizes, line counts and manual splitting remain tracked in MDI #85.

Metadata

Release files for illusion-markdown 2.1.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 illusion-markdown 2.1.0
File Size Uploaded
illusion_markdown-2.1.0.tar.gz 137.6 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for illusion-markdown 2.1.0
File
illusion_markdown-2.1.0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
illusion_markdown-2.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details
illusion_markdown-2.1.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
illusion_markdown-2.1.0-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details

Total release size: 4.1 MB

Release files / illusion_markdown-2.1.0.tar.gz

Download URL illusion_markdown-2.1.0.tar.gz
Size 137.6 kB
Tags Source
SHA-256 checksum
How to use checksums
ba44fa7a1e1988d68a580111c2a9a3d00b8cbd7972ce03616592de7ca839e615
BLAKE2b-256 checksum
How to use checksums
72bcbe5f22c4acb372356656913fb070d4f66477f1b3ffc355cae992725127f1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 13, 2026.

Transparency log

Release files / illusion_markdown-2.1.0-cp310-abi3-win_amd64.whl

Download URL illusion_markdown-2.1.0-cp310-abi3-win_amd64.whl
Size 870.5 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
6a76c2d4d24ec017d0c45e7d6bad5d8d0c257be390f5ba741aa4c713c1394965
BLAKE2b-256 checksum
How to use checksums
4f21b9d7aa0dfb8885a3b1062905a2dd5b6c3688720a52ea2009f60c5d30cde7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 13, 2026.

Transparency log

Release files / illusion_markdown-2.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL illusion_markdown-2.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.1 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
842eec96e56828ca9bd06d65a8830a21a4ed4dcc8cadac03de9a1d811e9f3bf2
BLAKE2b-256 checksum
How to use checksums
157dc0d507d441ee64e11014fa772c6b10a9664a39fabf558852ae81db06d7af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 13, 2026.

Transparency log

Release files / illusion_markdown-2.1.0-cp310-abi3-macosx_11_0_arm64.whl

Download URL illusion_markdown-2.1.0-cp310-abi3-macosx_11_0_arm64.whl
Size 986.9 kB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
7c8e7fa65be2d1651a088d3a7cd361f9e5fe4dbab39a222ef564508058b1b605
BLAKE2b-256 checksum
How to use checksums
d4fb108799fb76357aa47cd38754bcfc4c94e13362fdefd302f828117a61e943
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 13, 2026.

Transparency log

Release files / illusion_markdown-2.1.0-cp310-abi3-macosx_10_12_x86_64.whl

Download URL illusion_markdown-2.1.0-cp310-abi3-macosx_10_12_x86_64.whl
Size 1.0 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
38e259dcb7750c6b88bbafdf37d64d3a40a21fbba050c3413c3043eb55bd2bd5
BLAKE2b-256 checksum
How to use checksums
7379a27bb316a6d885046a79d0e9b80aaf73355c3fdfced4718b58f404267d52
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 13, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

2.1.0 This release

5 release files

2.0.5

5 release files

2.0.4

5 release files

2.0.3

5 release files

2.0.2

5 release files

2.0.1

5 release files

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