Skip to main content

A markdown parser

Project description

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

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

meltdown-0.0.7.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

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

meltdown-0.0.7-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file meltdown-0.0.7.tar.gz.

File metadata

  • Download URL: meltdown-0.0.7.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.14.0

File hashes

Hashes for meltdown-0.0.7.tar.gz
Algorithm Hash digest
SHA256 eee5602e7111b1dc3582a6e17c0d91d1b2214f2d7435565741cac5e82ee70ec6
MD5 60bc57c24a8c313f6eaf3c005c52c6c1
BLAKE2b-256 97b5af01837ff04bc0893c342ad4873297a3565a01d4f8b744730b9771990b93

See more details on using hashes here.

File details

Details for the file meltdown-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: meltdown-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.14.0

File hashes

Hashes for meltdown-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 8f67b1899e000a5a0da132af0ea3957033d955ad4979519064eb7511d7ddf533
MD5 55a8cfc821afd1ba57fb36fb772712cb
BLAKE2b-256 17d1fc684efdf803507bcb4b6ce609cfc7824f4490de4b0f56b8493965f571e5

See more details on using hashes here.

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