Skip to main content

Professional terminal markdown renderer for streaming LLM responses

Project description

MarkRender

MarkRender is a Python library for rendering Markdown in the terminal. It is designed to be highly customizable and is particularly well-suited for streaming content, such as responses from Large Language Models (LLMs).

Key Features

  • Streaming Support: MarkRender can process and render Markdown content as it arrives, providing a smooth and responsive experience for dynamic content.
  • Syntax Highlighting: Code blocks are highlighted using the powerful Pygments library, supporting a wide range of languages.
  • Theming: Choose from a variety of built-in themes to customize the appearance of your rendered output.
  • Table Rendering: Tables are rendered with proper formatting and alignment, powered by the rich library.
  • Markdown Compatibility: Supports a wide range of Markdown features, including headings, lists, blockquotes, and more.
  • Cross-Platform: Works on Windows, macOS, and Linux.

Installation

You can install MarkRender using pip:

pip install markrender

For development, you can clone the repository and install it in editable mode:

git clone https://github.com/Praneeth-Gandodi/markrender.git
cd markrender
pip install -e .

Basic Usage

To render a Markdown string, create a MarkdownRenderer instance and use its render method:

from markrender import MarkdownRenderer

renderer = MarkdownRenderer()

markdown_text = """
# Example Document

This is a sample Markdown document to demonstrate the capabilities of MarkRender.

## Text Formatting

You can use various text formatting options, such as:

- **Bold text**
- *Italic text*
- `Inline code`

## Code Blocks

```python
def hello_world():
    print("Hello, from MarkRender!")
```

## Tables

| Feature         | Supported |
| --------------- | :-------: |
| Streaming       |    Yes    |
| Syntax Highlighting |    Yes    |
| Theming         |    Yes    |

"""

renderer.render(markdown_text)
renderer.finalize()

Streaming Usage

MarkRender is ideal for rendering content that arrives in chunks, such as from an API response. The render method can be called multiple times with partial content.

import time
from markrender import MarkdownRenderer

renderer = MarkdownRenderer()

markdown_stream = [
    "# Streaming Example\n\n",
    "This text is being rendered in chunks.\n\n",
    "```python\n",
    "for i in range(5):\n",
    "    print(i)\n",
    "```\n",
]

for chunk in markdown_stream:
    renderer.render(chunk)
    time.sleep(0.5)

renderer.finalize()

Customization

The MarkdownRenderer can be customized with various options:

from markrender import MarkdownRenderer

renderer = MarkdownRenderer(
    theme='monokai',
    line_numbers=True,
    code_background=True,
    force_color=True,
    stream_code=True
)

Available Options:

  • theme: The color theme to use for syntax highlighting.
  • line_numbers: Whether to display line numbers in code blocks.
  • code_background: Whether to add a background color to code blocks.
  • force_color: If True, forces color output even if the terminal does not appear to support it.
  • stream_code: If False, code blocks are rendered all at once at the end, rather than line by line.

Available Themes

  • github-dark
  • monokai
  • dracula
  • nord
  • one-dark
  • solarized-dark
  • solarized-light

Contributing

Contributions are welcome! Please feel free to open an issue or submit a pull request on the GitHub repository.

License

MarkRender is distributed under the MIT License. See the LICENSE file for more details.

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

markrender-1.0.2.tar.gz (32.9 kB view details)

Uploaded Source

Built Distribution

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

markrender-1.0.2-py3-none-any.whl (22.1 kB view details)

Uploaded Python 3

File details

Details for the file markrender-1.0.2.tar.gz.

File metadata

  • Download URL: markrender-1.0.2.tar.gz
  • Upload date:
  • Size: 32.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for markrender-1.0.2.tar.gz
Algorithm Hash digest
SHA256 1657f0dfbb27460b86053e6566fe34efad41ba5eb2f8a4ccbc73f388746d1ddd
MD5 be207572a56705fea4489b9d2a1ba6cb
BLAKE2b-256 3aabb312e7fa2f5c59231409888a4978afe5125cffb9b911ccf246f3d12e4dae

See more details on using hashes here.

File details

Details for the file markrender-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: markrender-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 22.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for markrender-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c44a2286be4147230667a97b09fa8411d81d9be468cca869374157d24a172274
MD5 bd3e8afa63c788e9c02ae35f07add031
BLAKE2b-256 caef153e403576cb09d696ef47f25581a7b51b6ae959906c7889d41736b23f8d

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