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
richlibrary. - 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.
```python
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: IfTrue, forces color output even if the terminal does not appear to support it.stream_code: IfFalse, code blocks are rendered all at once at the end, rather than line by line.
Available Themes
github-darkmonokaidraculanordone-darksolarized-darksolarized-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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file markrender-1.0.1.tar.gz.
File metadata
- Download URL: markrender-1.0.1.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
624d047b364695175ff3d99f10cc1cded6e6126d6822ded9d4b7551bf493320e
|
|
| MD5 |
bd727d5d653d5f4df1114452d36c3b36
|
|
| BLAKE2b-256 |
0ff3f1e6f25123b0142ababfdda20d7a6fd82ce6114584aacb445e489c504451
|
File details
Details for the file markrender-1.0.1-py3-none-any.whl.
File metadata
- Download URL: markrender-1.0.1-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c0ced0e16cea6b1b351bab13048de9caa27bff64d0b3d66ef2f84a11f48899cd
|
|
| MD5 |
63b4a58b500ba1ba696268f9a0bf6796
|
|
| BLAKE2b-256 |
27873ac0c7817ea5f15885248d1e054d96d963a412b794b18647897dbe9f5455
|