Markdown = Air Tags + Mistletoe
- Free software: MIT License
- Documentation: https://air-markdown.readthedocs.io.
- Handy
Markdown()
Air Tag that renders Markdown into HTML. - Powerful
AirMarkdown()
Air Tag that renders Markdown into HTML, including rendering of Air Tags inside ````air-live``` blocks. For example, if you have:
air.H2("Heading 2")
it will render as <h2>Heading 2</h2>
.
Via uv:
uv add air-markdown
Or pip:
pip install air-markdown
from air_markdown import Markdown
Markdown('# Hello, world')
Renders as:
<h1>Hello, world.</h1>
Mistletoe allows for customization of the renderer through overloading of the Markdown.html_renderer
property.
from air_markdown import Markdown
import mistletoe
class SupermanRenderer(mistletoe.HtmlRenderer):
def render_strong(self, token: mistletoe.span_token.Strong) -> str:
template = '<strong class="superman">{}</strong>'
return template.format(self.render_inner(token))
Markdown.html_renderer = SupermanRenderer
Now Markdown("**Look in the sky!**")
renders
<p><strong class="superman">Look in the sky!</strong></p>\n
If you need to wrap Markdown output, just override the Markdown.wrapper
. So if you need all content to be wrapped by a section
tag:
Markdown.wrapper = lambda self, x: f'<section>{x}</section>'
assert Markdown('# Big').render() == '<section><h1>Big</h1>\n</section>'
Useful for when using Tailwind Typography, it wraps content in an <article class="prose">
tag.
html = TailwindTypographyMarkdown('# Tailwind support').render()
assert html == '<article class="prose"><h1>Tailwind support</h1>\n</article>'
This package was created with Cookiecutter and the audreyfeldroy/cookiecutter-pypackage project template.