Metadata-Version: 2.4
Name: rich-typography
Version: 0.2.0
Summary: Large letter typography for Rich and Textual
Author: Matthias Kalms
Author-email: Matthias Kalms <mtkalms@gmail.com>
License-Expression: MIT
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Operating System :: Microsoft :: Windows :: Windows 10
Classifier: Operating System :: Microsoft :: Windows :: Windows 11
Classifier: Operating System :: MacOS
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Typing :: Typed
Requires-Dist: rich>=14.2.0
Requires-Python: >=3.9
Project-URL: Bug Tracker, https://github.com/mtkalms/rich-typography/issues
Project-URL: Changelog, https://github.com/mtkalms/rich-typography/blob/main/CHANGELOG.md
Project-URL: Documentation, https://mtkalms.github.io/rich-typography
Project-URL: Homepage, https://github.com/mtkalms/rich-typography
Project-URL: Repository, https://github.com/mtkalms/rich-typography
Description-Content-Type: text/markdown

[![Test](https://github.com/mtkalms/rich-typography/actions/workflows/python-package.yml/badge.svg)](https://github.com/mtkalms/rich-typography/actions/workflows/python-package.yml)
[![Ruff](https://github.com/mtkalms/rich-typography/actions/workflows/ruff-format.yml/badge.svg)](https://github.com/mtkalms/rich-typography/actions/workflows/ruff-format.yml)
[![Documentation](https://github.com/mtkalms/rich-typography/actions/workflows/gh-pages.yml/badge.svg)](https://github.com/mtkalms/rich-typography/actions/workflows/gh-pages.yml)

# rich-typography
Large letter typography for [Rich](https://github.com/Textualize/rich) and [Textual](https://github.com/Textualize/textual).

![rich-typography example](https://github.com/mtkalms/rich-typography/raw/main/images/preview.svg)

## Installation

Install with `uv` or your favorite PYPI package manager:

```bash
uv add rich-typography
```

## Usage

```python
from 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-typography usage](https://github.com/mtkalms/rich-typography/raw/main/images/usage.svg)

### Custom Markdown

Rich allows you to create your own Markdown renderable and overwrite how specific markdown blocks are rendered.
With that we can modify [this example](https://rich.readthedocs.io/en/latest/markdown.html) to render H1 headings as `Typography` instead of `Text`.

```python
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)
```

![markdown example](https://github.com/mtkalms/rich-typography/raw/main/images/markdown.svg)

## Similar Projects

- [rich-pyfiglet](https://github.com/edward-jazzhands/rich-pyfiglet)
- [textual-pyfiglet](https://github.com/edward-jazzhands/textual-pyfiglet)