puku-markdown
A CommonMark‑compliant Markdown parser and renderer for block elements, written in pure Python with an explicit stack – no recursion, no hidden state, and a strong focus on readability and maintainability. Requires Python 3.12 or higher.
Motivation
While markdown-it-py is a solid parser, its codebase has several pain points that this project addresses:
- Recursive descent → explicit stack –
puku-markdownuses an explicit stack, eliminating recursion limits and improving portability (e.g., to C). For example,markdown-it-pyrelies on recursion and a mutablestate.tightflag that becomes inconsistent across nested lists;puku-markdownstores per‑level state on an explicit stack instead. - No obscure quirks – Removes confusing state flags like
sCount = -1for continuation. - Readability first – Clean variable names, thorough comments, and a well‑structured codebase.
- Designed for long‑term maintenance – Every internal detail is documented and intentional.
This library was born from a deep refactoring attempt of
markdown-it-py. Instead of fighting the original code, we built a fresh, cleaner implementation.
Features
- ✅ CommonMark block elements – headings, code blocks, lists, blockquotes, HTML blocks, thematic breaks, and more.
- ✅ Explicit stack – no recursion, easy to reason about and port.
- ✅ Pure Python – no external runtime dependencies.
- ✅ Renderer – currently supports rendering back to plain Markdown (text).
- ✅ Tested against
markdown-it-py– we reuse their extensive test suite for compliance.
Current status: Block elements are fully supported for both parsing and rendering. Inline elements (emphasis, links, images, etc.) are planned.
Installation
pip install puku-markdown
Or with uv (recommended):
uv add puku-markdown
Quick Usage
from puku_markdown import parse, render_to_text
# Parse Markdown to an AST.
document = parse("""
# Heading
- List item 1
- List item 2
> A blockquote.
""")
# Render the AST back to Markdown text.
rendered = render_to_text(document)
print(rendered)
Development
Clone the repository and set up the environment:
git clone https://github.com/curlinkw/puku-markdown.git
cd puku-markdown
uv sync --group test
Run tests:
uv run pytest
Contributing
Issues and pull requests are welcome. Please ensure that changes pass the CommonMark test suite and maintain 100% compatibility for the supported block elements.
License
MIT License. See LICENSE for details.
Metadata
Release files for puku-markdown 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| puku_markdown-0.2.1.tar.gz | 173.3 kB | Without provenance | Details for puku_markdown-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| puku_markdown-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for puku_markdown-0.2.1-py3-none-any.whl |
Total release size: 281.4 kB
Release files / puku_markdown-0.2.1.tar.gz
| Download URL | puku_markdown-0.2.1.tar.gz |
|---|---|
| Size | 173.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c6adff454f77467d6b050d582d7afb5cfbf4b76f0acafed4afa0ad7b508752b3
|
|
BLAKE2b-256 checksum How to use checksums |
28cb65b168211a2f5cbc22ed423d7f35162fcfc31c17e863f5384692c457eedf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / puku_markdown-0.2.1-py3-none-any.whl
| Download URL | puku_markdown-0.2.1-py3-none-any.whl |
|---|---|
| Size | 108.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f76e49b13165606f9693652315c0a7227bd246248eb69114bd2a6ff0d4dde0aa
|
|
BLAKE2b-256 checksum How to use checksums |
d06a35a60f7ffa20624ab3b0a6c02974b61b9c18c39fff17444754a4f74673ab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Security for puku-markdown 0.2.1
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.