Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/flofriday/meltdown
A naive markdown parser in python
https://github.com/flofriday/meltdown
Last synced: 1 day ago
JSON representation
A naive markdown parser in python
- Host: GitHub
- URL: https://github.com/flofriday/meltdown
- Owner: flofriday
- License: mit
- Created: 2024-04-17T19:02:02.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-05-17T11:34:45.000Z (8 months ago)
- Last Synced: 2025-01-04T04:46:34.976Z (22 days ago)
- Language: Python
- Size: 34.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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.
```bash
pip install meltdown
```## Usage
```python
from meltdown import MarkdownParser, HtmlProducerdoc = MarkdownParser().parse("# Hello **friends**!")
html = HtmlProducer().produce(doc)print(doc.dump())
print(html)
```The default `HtmlProducer` is heavily inspired by [pandoc](https://pandoc.org),
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 `` to ``:
```python
from meltdown import MarkdownParser, HtmlProducer
from meltdown.Nodes import *
from typing import Selfclass CustomHtmlProducer(HtmlProducer):
def visit_bold(self: Self, node: BoldNode):
self._output += ""
for child in node.children:
child.accept(self)
self._output += ""doc = MarkdownParser().parse("# Hello **friends**!")
html = CustomHtmlProducer().produce(doc)print(html)
```## Run all tests
```bash
python -m pytest
```