Skip to main content

A fast, extensible Markdown parser in pure Python.

Project description

markcraft

Your next Markdown parser in Python: pure Python, CommonMark-oriented, and easy to extend.

Why You Will Like It

  • Pure Python, no C extension burden: simpler deployment across environments.
  • CommonMark-oriented behavior: predictable parsing with stable token precedence.
  • Extensible architecture: add custom block/span tokens and custom renderers.
  • More than HTML output: ships with HTML, LaTeX, AST, and Markdown renderers.
  • Built for maintainability: parser and renderer responsibilities stay cleanly separated.

Installation

Install from PyPI:

pip install markcraft

Local development setup (uv + Python 3.13):

git clone https://github.com/niu2x/markcraft.git
cd markcraft
uv sync

30-Second Quick Start

1) Render to HTML by default

import markcraft

with open("example.md", "r", encoding="utf-8") as fin:
    html = markcraft.render(fin)

2) Use a specific renderer (for example, LaTeX)

import markcraft
from markcraft.renderers import LaTeXRenderer

with open("example.md", "r", encoding="utf-8") as fin:
    latex = markcraft.render(fin, LaTeXRenderer)

3) Parse explicitly when you need a Document tree

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)

Why call markcraft.parse(...) twice here?

  • doc = markcraft.parse(...) uses the default parser path and returns a generic Document tree.
  • markcraft.parse(..., renderer) parses with renderer context, so renderer-specific token rules are included when needed.
  • Use the first form for renderer-agnostic analysis; use the second form when your renderer adds or depends on extra syntax.

Outputs and Extensions

Core renderers

  • markcraft.renderers.HtmlRenderer
  • markcraft.renderers.LaTeXRenderer
  • markcraft.renderers.AstRenderer
  • markcraft.renderers.MarkdownRenderer

Extension renderers

Import directly from extension modules:

  • markcraft.extensions.mathjax.MathJaxRenderer
  • markcraft.extensions.pygments_renderer.PygmentsRenderer
  • markcraft.extensions.toc_renderer.TocRenderer
  • markcraft.extensions.github_wiki.GithubWikiRenderer
  • markcraft.extensions.jira_renderer.JiraRenderer
  • markcraft.extensions.xwiki20_renderer.XWiki20Renderer
  • markcraft.extensions.scheme.SchemeRenderer

Or import from the aggregated namespace:

  • markcraft.renderers.extensions.GithubWikiRenderer
  • markcraft.renderers.extensions.JiraRenderer
  • markcraft.renderers.extensions.MathJaxRenderer
  • markcraft.renderers.extensions.PygmentsRenderer
  • markcraft.renderers.extensions.SchemeRenderer
  • markcraft.renderers.extensions.TocRenderer
  • markcraft.renderers.extensions.XWiki20Renderer

For Contributors

Use uv and Python 3.13 for local development.

uv sync
uv run pytest

For benchmarks:

uv sync --group benchmark
uv run python tests/benchmark.py

More implementation details: DEVELOPMENT.md and BENCHMARKING.md.

Contributing

Issues, discussions, and pull requests are welcome.

  • For larger changes, open an issue first with context and a minimal reproduction.
  • Keep code contributions focused and add tests under tests/.

Versioning and License

  • Licensed under MIT. See LICENSE.

Project Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

markcraft-1.0.2.tar.gz (39.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

markcraft-1.0.2-py3-none-any.whl (56.0 kB view details)

Uploaded Python 3

File details

Details for the file markcraft-1.0.2.tar.gz.

File metadata

  • Download URL: markcraft-1.0.2.tar.gz
  • Upload date:
  • Size: 39.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for markcraft-1.0.2.tar.gz
Algorithm Hash digest
SHA256 532cd3081faf0b58a6dd8e1ff411cb3a3bdd5049462d042b45eb7541ce5bb22c
MD5 fa024683d3a5caf2bb64e7ceeb9ba54e
BLAKE2b-256 8f990f1c2c8438a1c0f8272be6937d6776424ae8893fd0ea41772c7e058e26f5

See more details on using hashes here.

Provenance

The following attestation bundles were made for markcraft-1.0.2.tar.gz:

Publisher: publish-pypi.yml on niu2x/markcraft

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file markcraft-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: markcraft-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 56.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for markcraft-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2cfa3324f941e988e3595ed04207ff0f3095dd07ed48e0b64c10a01e88495467
MD5 eab7df7ff4932501321f7f61bee0cf7d
BLAKE2b-256 0b7d0de55a3448fa847c29c70d43f0bc215b207162f6d1e9fac2ccd8438985ea

See more details on using hashes here.

Provenance

The following attestation bundles were made for markcraft-1.0.2-py3-none-any.whl:

Publisher: publish-pypi.yml on niu2x/markcraft

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page