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.

Installation

Via pip:

pip install air-markdown

or uv:

uv add 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.2.1.tar.gz (4.8 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.2.1-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for air_markdown-0.2.1.tar.gz
Algorithm Hash digest
SHA256 b1352741ce3a22f4d49a8c268d73f9239f5d7940cdfa915bd862526652ff976a
MD5 e173a6a3a7815c4e5e60211154536cac
BLAKE2b-256 02e969cada4bd0b4c871ee75bd56797554368160546fd82c2d448a88cbb4f212

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for air_markdown-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5ed1534f7db6cc04ef748c00a14c40446c18a32a4b96a1309c0b5e3a8b679fa7
MD5 de30f81dc1f528216a79044a70ac1ac5
BLAKE2b-256 1ec077d08f01f9a0eb214adc89603b7271e71fa8de18394d8ff7c7da2de263d4

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