Skip to main content

Air Tags + Markdown

Project description

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.

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

air_markdown-0.3.0.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

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

air_markdown-0.3.0-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file air_markdown-0.3.0.tar.gz.

File metadata

  • Download URL: air_markdown-0.3.0.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.3

File hashes

Hashes for air_markdown-0.3.0.tar.gz
Algorithm Hash digest
SHA256 9007861eab6aa97018486a92a1f3de5e90cb3b82ca51f07e02e0b3f3cf29b035
MD5 7c8eee760543f1e5cbf058b2f5cc2e66
BLAKE2b-256 f3101cd4fd2f709ed379b817d9144fe2a3039e8d3321b28f007a0faf69af54e3

See more details on using hashes here.

File details

Details for the file air_markdown-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for air_markdown-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 960c0b7921acde83545c482580bc428f24c72cba72611b08b37e7d5552ddfe5d
MD5 5a15abec710b54da308d27fa2a945a3e
BLAKE2b-256 97925e7e5c68cfdd9905eb33e935d43d4b8986d9fcbb200f824a994b9fb90671

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