Skip to content

feldroy/air-markdown

Repository files navigation

air-markdown

PyPI version

Markdown = Air Tags + Mistletoe

Features

  • 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>.

Installation

Via uv:

uv add air-markdown

Or pip:

pip install air-markdown

Usage

from air_markdown import Markdown

Markdown('# Hello, world')

Renders as:

<h1>Hello, world.</h1>

Customizing the rendered HTML

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

Wrapping Markdown output

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>'

TailwindTypographyMarkdown()

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>'

Credits

This package was created with Cookiecutter and the audreyfeldroy/cookiecutter-pypackage project template.

About

No description, website, or topics provided.

Resources

License

Code of conduct

Stars

Watchers

Forks

Sponsor this project

  •  
  •  
  •  

Packages

No packages published

Contributors 2

  •  
  •