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)

Run all tests

uv run pytest

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.6.tar.gz (5.4 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.6-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for meltdown-0.0.6.tar.gz
Algorithm Hash digest
SHA256 7004a89dc6c8e845530aa9aedb946c9feac30eda6a4abc677bce1caaa29495b9
MD5 74dff0a63ad8b6cb9646eb62b0d88a05
BLAKE2b-256 3f9072e0d540214515eb4aaf929df02301cb957098fda68a1ebeb7c5a5d18ec0

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for meltdown-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 99c93b8c7f51dad8a167a7e1737c86c73414fa46377282b369f45f223b6c790b
MD5 daa27f7ea7da019c8f392f2ad7459bed
BLAKE2b-256 3141ae43fb49790ca72018afe99e610a57bd3b5de91f972b373fcf204bfbcbec

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