Skip to main content

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.HtmlRenderer
  • markcraft.renderers.LaTeXRenderer
  • markcraft.renderers.AstRenderer
  • markcraft.renderers.MarkdownRenderer

Contrib renderers

  • 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
  • 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

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-publish with 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

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.0.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.0-py3-none-any.whl (54.6 kB view details)

Uploaded Python 3

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

Hashes for markcraft-1.0.0.tar.gz
Algorithm Hash digest
SHA256 be314c36cba2b9f2febf9fbfdf4cc5caee84e5731ce3ed12a984ab15518a851d
MD5 5f53e5ead5d314c4e9c9e2697443c4cd
BLAKE2b-256 5031bcf5fcce9e745c595a004b6ab8af82cf928aa6de71050b7a6489cb5b9b1c

See more details on using hashes here.

Provenance

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

Hashes for markcraft-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cbdaa2b54ba8adffb25bb2e06af275b06c5a3b9581ef0e67d9a0218d5cbde78d
MD5 fa64407a0655fb7e29c341680e95c3f9
BLAKE2b-256 c3b4653abe062a2dc673a6cdcce1d4c17d8c8b993d0e6e4bd4b88b5627cbe8ae

See more details on using hashes here.

Provenance

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