Large letter typography for Rich and Textual.
Install with uv or your favorite PYPI package manager:
uv add rich-typographyfrom rich.console import Console
from rich_typography import Typography
console = Console()
text = Typography.from_markup("Hello from [purple]rich-typography[/purple]")
console.print(text)Rich allows you to create your own Markdown renderable and overwrite how specific markdown blocks are rendered.
With that we can modify this example to render H1 headings as Typography instead of Text.
from rich.markdown import Markdown as RichMarkdown, Heading as RichHeading
from rich.console import Console, RenderResult
from rich_typography import Typography
MARKDOWN = """
# This is an h1
Rich can do a pretty *decent* job of rendering markdown.
## This is an h2
1. This is a list item
2. This is another list item
"""
class Heading(RichHeading):
def __rich_console__(self, *args, **kwargs) -> RenderResult:
self.text.style = "red"
if self.tag == "h1":
text = Typography.from_text(self.text)
text.justify = "center"
yield text
else:
yield from super().__rich_console__(*args, **kwargs)
class Markdown(RichMarkdown):
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
self.elements["heading_open"] = Heading
output = Markdown(MARKDOWN)- Allows you to use any font
- Depends on terminal supporting terminal graphics protocol (TPG) or sixel graphics protocol
- Layout is more difficult to control
from PIL import Image, ImageDraw, ImageFont
from textual_image.renderable import Image as RichImage
from rich.console import Console
img = Image.new("RGBA", (500, 64))
draw = ImageDraw.Draw(img)
font = ImageFont.truetype("CascadiaCode.ttf", 64)
draw.text((0, 0), "This is an h1", font=font, fill=(255, 0, 0))
console = Console()
console.print(RichImage(img))TGP:
Sixel:
Half block fallback:
Kitty has proposed a text sizing protocol but support by popular terminals is currently still limited.


