Skip to main content

meltdown

A naive Markdown parser in pure Python.

WARNING: The library will never attempt to do any sanitization on the input. If used for user generated content it is highly recommended to use an external sanitization library.

Installation

meltdown currently only supports Python 3.12.

pip install meltdown

Usage

from meltdown import MarkdownParser, HtmlProducer

doc = MarkdownParser().parse("# Hello **friends**!")
html = HtmlProducer().produce(doc)

print(doc.dump())
print(html)

The default HtmlProducer is heavily inspired by pandoc, however, if you are unhappy you can easily write your own producer or if only some formattings are unwanted override the default methods.

In the following example we change the bold formatting form <strong> to <b>:

from meltdown import MarkdownParser, HtmlProducer
from meltdown.Nodes import *
from typing import Self

class CustomHtmlProducer(HtmlProducer):
    def visit_bold(self: Self, node: BoldNode):
        self._output += "<b>"
        for child in node.children:
            child.accept(self)
        self._output += "<b>"

doc = MarkdownParser().parse("# Hello **friends**!")
html = CustomHtmlProducer().produce(doc)

print(html)

Development

To quickly test some stuff there is a cli that consumes the library which you can run with:

usage: meltdown-dev-cli [-h] [--dump] filename

A cli for developers trying meltdown

positional arguments:
  filename    Name of the file being parsed and converted.

options:
  -h, --help  show this help message and exit
  --dump      Print the dump instead of the html.
uv run cli.py tests/blog/post-jit.md

Run all tests

uv run pytest

Most of our tests are snapshot tests which you can update with the following if you add new ones.

uv run pytest --inline-snapshot=create

Release files for meltdown 0.0.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for meltdown 0.0.8
File Size Uploaded
meltdown-0.0.8.tar.gz 5.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for meltdown 0.0.8
File Interpreter ABI Platform
meltdown-0.0.8-py3-none-any.whl Python 3 none any Details

Total release size:13.1 kB

Release files / meltdown-0.0.8.tar.gz

Download URL meltdown-0.0.8.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
6e69f00b9e39802c33daa291d575e1d013d4f9cd7d8bf6aed56c8df13db2d49c
BLAKE2b-256 checksum
How to use checksums
a89e2548b19930a6ea3d9f0c86bc765afc21137128e995bd0390d7c233f9f639
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.14.0

Release files / meltdown-0.0.8-py3-none-any.whl

Download URL meltdown-0.0.8-py3-none-any.whl
Size 7.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9ffe7233858e35d61ef3c9e5f0a53935e928f4b9c091b965fced153991b5c914
BLAKE2b-256 checksum
How to use checksums
995be2d21ddc73739a5c3fe226509e84df1739d4555013e2a81a93208c5dd25a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.14.0

Release history Release notifications | RSS feed

This release

0.0.8 This release

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page