Wenmode is a composable Markdown toolkit for Python by the same author as Mistune. It is a rewrite informed by Mistune’s design, with a stronger focus on explicit rule composition, mdast-compatible AST output, extension state, and pluggable rendering.
The top-level Wenmode class combines a parser and a renderer. By default, Wenmode parses CommonMark-style Markdown and renders HTML.
Documentation: https://wenmode.lepture.com
Use Wenmode to:
render Markdown to HTML with safe defaults for user-authored content,
choose the exact Markdown rules your application accepts,
inspect or store an mdast-compatible AST,
build a custom Markdown dialect with parser rules and renderer handlers,
stream HTML output from Markdown input.
Installation
pip install wenmode
Run the CLI without installing it permanently:
uvx wenmode render --preset=github README.md
uvx wenmode ast --preset=github README.md
After installation, use either the console script or Python module entry point:
wenmode render README.md --preset=github
python -m wenmode ast README.md --positions
Quick start
from wenmode import Wenmode
wen = Wenmode()
text = '''
# Hello
This is **wenmode**.
'''
expected = '''
<h1>Hello</h1>
<p>This is <strong>wenmode</strong>.</p>
'''
html = wen.render(text)
assert html == expected.lstrip()
Use parse() when you need the mdast-compatible syntax tree:
from wenmode import Wenmode
wen = Wenmode()
text = 'A [link](https://example.com).'
tree = wen.parse(text)
ast = tree.to_ast()
assert ast == {
'type': 'root',
'children': [
{
'type': 'paragraph',
'children': [
{'type': 'text', 'value': 'A '},
{
'type': 'link',
'children': [{'type': 'text', 'value': 'link'}],
'url': 'https://example.com',
},
{'type': 'text', 'value': '.'},
],
}
],
}
Set positions=True to include source ranges for editor integration, diagnostics, or AST-based tooling:
from wenmode import Wenmode
wen = Wenmode(positions=True)
ast = wen.parse('A **bold**.\n').to_ast()
assert ast['children'][0] == {
'type': 'paragraph',
'position': {
'start': {'line': 1, 'column': 1, 'offset': 0},
'end': {'line': 2, 'column': 1, 'offset': 12}
},
'children': [
{
'type': 'text',
'position': {
'start': {'line': 1, 'column': 1, 'offset': 0},
'end': {'line': 1, 'column': 3, 'offset': 2}
},
'value': 'A '
},
{
'type': 'strong',
'position': {
'start': {'line': 1, 'column': 3, 'offset': 2},
'end': {'line': 1, 'column': 11, 'offset': 10}
},
'children': [
{
'type': 'text',
'position': {
'start': {'line': 1, 'column': 5, 'offset': 4},
'end': {'line': 1, 'column': 9, 'offset': 8}
},
'value': 'bold'
}
]
},
{
'type': 'text',
'position': {
'start': {'line': 1, 'column': 11, 'offset': 10},
'end': {'line': 1, 'column': 12, 'offset': 11}
},
'value': '.'
}
]
}
Pass a renderer when you need reStructuredText or AsciiDoc output:
from wenmode import AsciiDocRenderer, Wenmode
wen = Wenmode(renderer=AsciiDocRenderer())
text = '# Hello'
expected = '= Hello\n'
asciidoc = wen.render(text)
assert asciidoc == expected
Rules, presets, and plugins
Most applications start with a preset:
commonmark, the default CommonMark-style rule set,
github, for GitHub-flavored Markdown features such as tables and task lists,
streaming, for incremental HTML output.
Rules are opt-in and composable. Wenmode() uses the commonmark preset by default. Pass an explicit rule list to define a custom Markdown dialect.
from wenmode import Wenmode
from wenmode.rules import AtxHeading, FencedCode, Image, InlineCode, Link
wen = Wenmode([AtxHeading, FencedCode, Link, Image, InlineCode])
text = '''
# h1
hi `code` **strong**
'''
expected = '''
<h1>h1</h1>
<p>hi <code>code</code> **strong**</p>
'''
assert wen.render(text) == expected.lstrip()
Because Emphasis is not enabled above, **strong** stays as text.
Use Parser directly when you only need an AST and want to choose rendering separately:
from wenmode import HTMLRenderer, Parser
from wenmode.presets import commonmark
parser = Parser(commonmark)
text = '# Hello'
tree = parser.parse(text)
html = HTMLRenderer().render(tree)
Use the github preset for GitHub-flavored Markdown features such as tables, task lists, strikethrough, extended autolinks, and footnotes:
from wenmode import Wenmode
from wenmode.presets import github
wen = Wenmode(github)
Use built-in plugins for non-standard syntax, document metadata, and rendering behavior such as front matter, math, definition lists, abbreviations, spoilers, ruby text, HTML smart punctuation, and extra inline formatting:
from wenmode import Wenmode
from wenmode.plugins import inline_math
wen = Wenmode(plugins=[inline_math])
assert wen.render('Inline $x + y$.\n') == (
'<p>Inline <span class="math math-inline">x + y</span>.</p>\n'
)
Benchmark
Wenmode is designed so enabling more rules adds limited dispatch overhead. The benchmark script compares Markdown-to-HTML throughput across Wenmode and the libraries covered by the migration guides:
uv run --locked --group benchmark python scripts/benchmark.py --case all
wenmode-core uses CommonMark-style rules plus pipe tables. It disables raw HTML passthrough and URL sanitization to match the other HTML renderers. Mistune, Python-Markdown, markdown-it-py, and markdown2 enable table support. Marko uses its broader GFM helper. commonmark.py is a CommonMark-only baseline because it does not support pipe tables.
wenmode-all uses the github preset plus Wenmode’s built-in plugins, including front matter, math, definition lists, abbreviations, spoilers, ruby text, heading IDs, GitHub alerts, and additional inline formatting. The benchmark corpora use few of these extra rules. This target measures rule dispatch overhead, not equivalent syntax coverage.
All benchmark targets are created once before warmup and timed iterations, then reused for every render call. Python-Markdown resets the same reusable Markdown instance before each conversion.
Versions used in these snapshots:
Library |
Version |
|---|---|
wenmode |
0.11.0 |
mistune |
3.3.3 |
python-markdown |
3.10.2 |
markdown-it-py |
4.2.0 |
markdown2 |
2.5.5 |
marko |
2.2.3 |
commonmark.py |
0.9.2 |
Mean time from one local Python 3.12.9 --case all run:
Case |
Bytes |
Library |
Mean |
MB/s |
vs core |
|---|---|---|---|---|---|
docs |
135,115 |
wenmode-core |
18.08ms |
7.84 |
1.00x |
docs |
135,115 |
wenmode-all |
20.70ms |
6.56 |
0.87x |
docs |
135,115 |
mistune |
25.42ms |
5.85 |
0.71x |
docs |
135,115 |
python-markdown |
76.18ms |
1.84 |
0.24x |
docs |
135,115 |
markdown-it-py |
39.21ms |
3.61 |
0.46x |
docs |
135,115 |
markdown2 |
158.86ms |
0.88 |
0.11x |
docs |
135,115 |
marko |
144.15ms |
1.00 |
0.13x |
docs |
135,115 |
commonmark.py |
90.95ms |
1.63 |
0.20x |
rust-book |
1,226,076 |
wenmode-core |
168.82ms |
7.80 |
1.00x |
rust-book |
1,226,076 |
wenmode-all |
181.23ms |
7.08 |
0.93x |
rust-book |
1,226,076 |
mistune |
222.76ms |
5.60 |
0.76x |
rust-book |
1,226,076 |
python-markdown |
588.23ms |
2.10 |
0.29x |
rust-book |
1,226,076 |
markdown-it-py |
337.53ms |
3.69 |
0.50x |
rust-book |
1,226,076 |
markdown2 |
4.129s |
0.30 |
0.04x |
rust-book |
1,226,076 |
marko |
1.107s |
1.12 |
0.15x |
rust-book |
1,226,076 |
commonmark.py |
10.046s |
0.12 |
0.02x |
progit |
502,090 |
wenmode-core |
28.90ms |
17.95 |
1.00x |
progit |
502,090 |
wenmode-all |
36.45ms |
15.32 |
0.79x |
progit |
502,090 |
mistune |
45.41ms |
11.94 |
0.64x |
progit |
502,090 |
python-markdown |
138.27ms |
3.72 |
0.21x |
progit |
502,090 |
markdown-it-py |
71.63ms |
7.73 |
0.40x |
progit |
502,090 |
markdown2 |
1.429s |
0.35 |
0.02x |
progit |
502,090 |
marko |
338.29ms |
1.52 |
0.09x |
progit |
502,090 |
commonmark.py |
339.19ms |
1.52 |
0.09x |
In this run, wenmode-all remains faster than the other parsers even after loading many extra rules that the benchmark inputs mostly do not use.
Benchmark numbers depend on hardware, Python version, corpus, and parser configuration. See the full methodology in the Benchmarks documentation.
Streaming
Use the streaming preset to render HTML chunks before the complete document is parsed and rendered:
from wenmode import Wenmode
from wenmode.presets import streaming
wen = Wenmode(streaming)
text = '''
# Hello
A [link](/url).
'''
for chunk in wen.stream(text):
send(chunk)
Pass the returned iterator to a streaming response in Django, Flask, FastAPI, or another framework. The streaming preset keeps tables, strikethrough, direct links, and direct images enabled. It excludes reference-style links, footnotes, and other deferred document-wide transforms.
Learn more
Usage for the main APIs.
Presets for choosing a rule set.
Security for raw HTML and URL handling.
Plugins for built-in extensions.
Migration guides for moving from other Python Markdown parsers.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wenmode-0.13.3.tar.gz.
File metadata
- Download URL: wenmode-0.13.3.tar.gz
- Upload date:
- Size: 90.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6bf13141d4ee6c8bd472573c370b81d503ceda15681bb1c29710884d4660e1d5
|
|
| MD5 |
7649efc39c104b2d72aeffe2dae6acff
|
|
| BLAKE2b-256 |
41ea31ee8a723db3d95b59ab0a2cd18f75466dd6207db5edeab9c16bf3fdb30c
|
Provenance
The following attestation bundles were made for wenmode-0.13.3.tar.gz:
Publisher:
pypi.yml on lepture/wenmode
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
wenmode-0.13.3.tar.gz -
Subject digest:
6bf13141d4ee6c8bd472573c370b81d503ceda15681bb1c29710884d4660e1d5 - Sigstore transparency entry: 2342587660
- Sigstore integration time:
-
Permalink:
lepture/wenmode@a6ac36e580b68edbdd11a8d17c4eef503cda3437 -
Branch / Tag:
refs/tags/0.13.3 - Owner: https://github.com/lepture
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@a6ac36e580b68edbdd11a8d17c4eef503cda3437 -
Trigger Event:
push
-
Statement type:
File details
Details for the file wenmode-0.13.3-py3-none-any.whl.
File metadata
- Download URL: wenmode-0.13.3-py3-none-any.whl
- Upload date:
- Size: 137.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
91f3cece133fa3c24b239e68832b6fb10cea7a0af72731685fe0bdf84df88e8f
|
|
| MD5 |
c31cdaf534ec0602e9b942b4e3b90be2
|
|
| BLAKE2b-256 |
7f0fb4e5e7e664ce49fbe0049160b3c1abd34811be0e9083b1290f98c2c4909e
|
Provenance
The following attestation bundles were made for wenmode-0.13.3-py3-none-any.whl:
Publisher:
pypi.yml on lepture/wenmode
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
wenmode-0.13.3-py3-none-any.whl -
Subject digest:
91f3cece133fa3c24b239e68832b6fb10cea7a0af72731685fe0bdf84df88e8f - Sigstore transparency entry: 2342587897
- Sigstore integration time:
-
Permalink:
lepture/wenmode@a6ac36e580b68edbdd11a8d17c4eef503cda3437 -
Branch / Tag:
refs/tags/0.13.3 - Owner: https://github.com/lepture
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@a6ac36e580b68edbdd11a8d17c4eef503cda3437 -
Trigger Event:
push
-
Statement type: