A fast, extensible Markdown parser in pure Python.
Project description
markcraft
markcraft is a fast, extensible Markdown parser written in pure Python. It targets CommonMark behavior and keeps parser internals open for custom tokens and custom renderers.
Why markcraft
- Fast enough for large documents while staying pure Python.
- CommonMark-oriented parsing with deterministic token precedence.
- Extensible architecture for custom block/span tokens and renderers.
- Multiple built-in outputs: HTML, LaTeX, AST, and Markdown.
Installation
Install from PyPI:
pip install markcraft
For local development (uv + Python 3.13):
git clone https://github.com/niu2x/markcraft.git
cd markcraft
uv sync
Quick Start
Python API
import markcraft
with open("example.md", "r", encoding="utf-8") as fin:
html = markcraft.render(fin)
Use another renderer:
import markcraft
from markcraft.renderers.latex import LaTeXRenderer
with open("example.md", "r", encoding="utf-8") as fin:
latex = markcraft.render(fin, LaTeXRenderer)
Structured namespaces are also available:
from markcraft.renderers import HtmlRenderer
with HtmlRenderer() as renderer:
doc = renderer.parse("# hello\n")
html = renderer.render(doc)
Explicit parse entrypoints are available when you want parsing to be intentional:
import markcraft
from markcraft.renderers import MarkdownRenderer
doc = markcraft.parse("a\n\n[b]: /uri\n")
with MarkdownRenderer() as renderer:
renderer_specific_doc = markcraft.parse("a\n\n[b]: /uri\n", renderer)
markdown = renderer.render(renderer_specific_doc)
Output Formats
Core renderers
markcraft.renderers.HtmlRenderermarkcraft.renderers.LaTeXRenderermarkcraft.renderers.AstRenderermarkcraft.renderers.MarkdownRenderer
Contrib renderers
markcraft.extensions.mathjax.MathJaxRenderermarkcraft.extensions.pygments_renderer.PygmentsRenderermarkcraft.extensions.toc_renderer.TocRenderermarkcraft.extensions.github_wiki.GithubWikiRenderermarkcraft.extensions.jira_renderer.JiraRenderermarkcraft.extensions.xwiki20_renderer.XWiki20Renderermarkcraft.extensions.scheme.SchemeRenderermarkcraft.renderers.extensions.GithubWikiRenderermarkcraft.renderers.extensions.JiraRenderermarkcraft.renderers.extensions.MathJaxRenderermarkcraft.renderers.extensions.PygmentsRenderermarkcraft.renderers.extensions.SchemeRenderermarkcraft.renderers.extensions.TocRenderermarkcraft.renderers.extensions.XWiki20Renderer
Documentation Map
README.md: project overview, install, and usage.DEVELOPMENT.md: architecture, token model, renderer model, and extension points.BENCHMARKING.md: benchmark method, reproducibility, and optimization guidance.
Development
Common commands:
uv sync
uv run pytest
uv run python tests/benchmark.py
uv build
PyPI Publishing
This repository includes GitHub Actions automation for publishing to PyPI:
- Workflow:
.github/workflows/publish-pypi.yml - Trigger: push a tag like
v1.0.1(or run manually with workflow dispatch) - Build command:
uv build - Publish action:
pypa/gh-action-pypi-publishwith Trusted Publishing (OIDC)
Before first release, configure a Trusted Publisher on PyPI for this GitHub repository and workflow file.
For benchmark dependencies (markdown, mistune, commonmark), run:
uv sync --group benchmark
Contributing
Open an issue with context and a minimal reproduction before large changes.
For code contributions, keep commits focused and include tests in tests/.
Versioning and License
- Current version is defined in
src/markcraft/__init__.py. - Released under the MIT License. See
LICENSE.
Project Links
- Repository: https://github.com/niu2x/markcraft
- Issues: https://github.com/niu2x/markcraft/issues
- Actions: https://github.com/niu2x/markcraft/actions
- PyPI: https://pypi.org/project/markcraft/
Project details
Release history Release notifications | RSS feed
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 markcraft-1.0.0.tar.gz.
File metadata
- Download URL: markcraft-1.0.0.tar.gz
- Upload date:
- Size: 38.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
be314c36cba2b9f2febf9fbfdf4cc5caee84e5731ce3ed12a984ab15518a851d
|
|
| MD5 |
5f53e5ead5d314c4e9c9e2697443c4cd
|
|
| BLAKE2b-256 |
5031bcf5fcce9e745c595a004b6ab8af82cf928aa6de71050b7a6489cb5b9b1c
|
Provenance
The following attestation bundles were made for markcraft-1.0.0.tar.gz:
Publisher:
publish-pypi.yml on niu2x/markcraft
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
markcraft-1.0.0.tar.gz -
Subject digest:
be314c36cba2b9f2febf9fbfdf4cc5caee84e5731ce3ed12a984ab15518a851d - Sigstore transparency entry: 1340055080
- Sigstore integration time:
-
Permalink:
niu2x/markcraft@5d86fa73049a07744e7b8450019f19df06f38de8 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/niu2x
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@5d86fa73049a07744e7b8450019f19df06f38de8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file markcraft-1.0.0-py3-none-any.whl.
File metadata
- Download URL: markcraft-1.0.0-py3-none-any.whl
- Upload date:
- Size: 54.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cbdaa2b54ba8adffb25bb2e06af275b06c5a3b9581ef0e67d9a0218d5cbde78d
|
|
| MD5 |
fa64407a0655fb7e29c341680e95c3f9
|
|
| BLAKE2b-256 |
c3b4653abe062a2dc673a6cdcce1d4c17d8c8b993d0e6e4bd4b88b5627cbe8ae
|
Provenance
The following attestation bundles were made for markcraft-1.0.0-py3-none-any.whl:
Publisher:
publish-pypi.yml on niu2x/markcraft
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
markcraft-1.0.0-py3-none-any.whl -
Subject digest:
cbdaa2b54ba8adffb25bb2e06af275b06c5a3b9581ef0e67d9a0218d5cbde78d - Sigstore transparency entry: 1340055082
- Sigstore integration time:
-
Permalink:
niu2x/markcraft@5d86fa73049a07744e7b8450019f19df06f38de8 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/niu2x
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@5d86fa73049a07744e7b8450019f19df06f38de8 -
Trigger Event:
push
-
Statement type: