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.1.tar.gz (38.0 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.1-py3-none-any.whl (54.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: markcraft-1.0.1.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

Hashes for markcraft-1.0.1.tar.gz
Algorithm Hash digest
SHA256 4ffd07355fd26f5a8ad58abdc5a7e6e6a2e6a10efc9ef13c8a2c62ef8e40de1d
MD5 128101f5cbc5c89d5ef477c7f0be1fe6
BLAKE2b-256 1e35a36fa7227f85da10924b979d821dde40ccb20ea82f8c1470be8dd32a1da6

See more details on using hashes here.

Provenance

The following attestation bundles were made for markcraft-1.0.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: markcraft-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 54.5 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f9db2baabdf43592ee3bb1dc53a45a336b70aad1876b8677c27815ce5dc244be
MD5 8e60444b326e675484ed5761639d39a7
BLAKE2b-256 fb8d0e29653fb7f7861f97ce6e7c142fa717949b4da2218e17ca8d089989ac40

See more details on using hashes here.

Provenance

The following attestation bundles were made for markcraft-1.0.1-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