markrender 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. markrender-1.0.0/.gitignore +66 -0
  2. markrender-1.0.0/LICENSE +21 -0
  3. markrender-1.0.0/PKG-INFO +184 -0
  4. markrender-1.0.0/README.md +152 -0
  5. markrender-1.0.0/check_truecolor.py +30 -0
  6. markrender-1.0.0/examples/basic_usage.py +76 -0
  7. markrender-1.0.0/examples/streaming_demo.py +134 -0
  8. markrender-1.0.0/examples/theme_showcase.py +60 -0
  9. markrender-1.0.0/markrender/__init__.py +13 -0
  10. markrender-1.0.0/markrender/colors.py +158 -0
  11. markrender-1.0.0/markrender/formatters.py +462 -0
  12. markrender-1.0.0/markrender/parser.py +696 -0
  13. markrender-1.0.0/markrender/renderer.py +449 -0
  14. markrender-1.0.0/markrender/themes.py +193 -0
  15. markrender-1.0.0/markrender.egg-info/PKG-INFO +184 -0
  16. markrender-1.0.0/markrender.egg-info/SOURCES.txt +31 -0
  17. markrender-1.0.0/markrender.egg-info/dependency_links.txt +1 -0
  18. markrender-1.0.0/markrender.egg-info/requires.txt +8 -0
  19. markrender-1.0.0/markrender.egg-info/top_level.txt +1 -0
  20. markrender-1.0.0/pyproject.toml +44 -0
  21. markrender-1.0.0/setup.cfg +4 -0
  22. markrender-1.0.0/tests/__init__.py +1 -0
  23. markrender-1.0.0/tests/reproduce_code_block_colors.py +73 -0
  24. markrender-1.0.0/tests/reproduce_colors.py +130 -0
  25. markrender-1.0.0/tests/reproduce_failures.py +40 -0
  26. markrender-1.0.0/tests/test_emoji_note.py +27 -0
  27. markrender-1.0.0/tests/test_enhancements.py +104 -0
  28. markrender-1.0.0/tests/test_formatters.py +121 -0
  29. markrender-1.0.0/tests/test_inline_formatting_contexts.py +44 -0
  30. markrender-1.0.0/tests/test_parser.py +124 -0
  31. markrender-1.0.0/tests/test_renderer.py +276 -0
  32. markrender-1.0.0/tests/test_renderer_edge_cases.py +137 -0
  33. markrender-1.0.0/tests/verify_fixes.py +69 -0
@@ -0,0 +1,66 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ pip-wheel-metadata/
24
+ share/python-wheels/
25
+ *.egg-info/
26
+ .installed.cfg
27
+ *.egg
28
+ MANIFEST
29
+
30
+ # PyInstaller
31
+ *.manifest
32
+ *.spec
33
+
34
+ # Unit test / coverage reports
35
+ htmlcov/
36
+ .tox/
37
+ .nox/
38
+ .coverage
39
+ .coverage.*
40
+ .cache
41
+ nosetests.xml
42
+ coverage.xml
43
+ *.cover
44
+ *.py,cover
45
+ .hypothesis/
46
+ .pytest_cache/
47
+
48
+ # Virtual environments
49
+ venv/
50
+ ENV/
51
+ env/
52
+ .venv
53
+
54
+ # IDEs
55
+ .vscode/
56
+ .idea/
57
+ *.swp
58
+ *.swo
59
+ *~
60
+
61
+ # OS
62
+ .DS_Store
63
+ Thumbs.db
64
+
65
+ # Project specific
66
+ *.log
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Praneeth Gandodi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,184 @@
1
+ Metadata-Version: 2.4
2
+ Name: markrender
3
+ Version: 1.0.0
4
+ Summary: Professional terminal markdown renderer for streaming LLM responses
5
+ Author: Praneeth Gandodi
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/Praneeth-Gandodi/markrender
8
+ Project-URL: Documentation, https://github.com/Praneeth-Gandodi/markrender#readme
9
+ Project-URL: Repository, https://github.com/Praneeth-Gandodi/markrender
10
+ Project-URL: Bug Tracker, https://github.com/Praneeth-Gandodi/markrender/issues
11
+ Keywords: markdown,terminal,rendering,streaming,llm,cli
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.7
16
+ Classifier: Programming Language :: Python :: 3.8
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Requires-Python: >=3.7
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Requires-Dist: pygments~=2.19.2
25
+ Requires-Dist: emoji~=2.15.0
26
+ Requires-Dist: rich~=14.3.2
27
+ Requires-Dist: colorama~=0.4.6
28
+ Provides-Extra: dev
29
+ Requires-Dist: pytest~=6.0.0; extra == "dev"
30
+ Requires-Dist: pytest-cov~=2.10.0; extra == "dev"
31
+ Dynamic: license-file
32
+
33
+ # MarkRender 🎨
34
+
35
+ **A professional terminal markdown renderer built for streaming LLM responses.**
36
+
37
+ MarkRender is a Python library designed to bring beautifully rendered markdown directly to your terminal. It's especially good for displaying streaming output from large language models, ensuring a smooth, flicker-free experience with rich formatting and syntax highlighting.
38
+
39
+ ## ✨ Features You'll Love
40
+
41
+ * **Streaming Optimized**: Renders markdown chunks as they arrive, perfect for LLM interactions.
42
+ * **Gorgeous Themes**: Comes with several built-in color themes to match your terminal aesthetic.
43
+ * **Smart Syntax Highlighting**: Powered by Pygments, it makes your code blocks pop.
44
+ * **Full Markdown Support**: Handles everything from headings and lists to tables, checkboxes, emojis, and links with robust streaming support.
45
+ * **Cross-Platform**: Works on Windows, macOS, and Linux.
46
+
47
+ ## 🚀 Get Started
48
+
49
+ ### Installation
50
+
51
+ It's super easy to get MarkRender up and running:
52
+
53
+ ```bash
54
+ pip install git+https://github.com/Praneeth-Gandodi/markrender.git
55
+ ```
56
+
57
+ Or, for development, clone the repository and install in editable mode:
58
+ ```bash
59
+ git clone https://github.com/Praneeth-Gandodi/markrender.git
60
+ cd markrender
61
+ pip install -e .
62
+ ```
63
+
64
+ ### Quick Usage
65
+
66
+ Here's how to render a simple markdown string
67
+
68
+ ```python
69
+ from markrender import MarkdownRenderer
70
+
71
+ renderer = MarkdownRenderer()
72
+
73
+ markdown_text = """
74
+ # Project Title
75
+ This is a comprehensive markdown example that demonstrates various features.
76
+ It includes headers, lists, links, images, and code blocks.
77
+
78
+ ## Subsection Explanation
79
+ - **Headers** are defined using `#` symbols.
80
+ - **Lists** can be ordered or unordered.
81
+ - **Links** use the syntax: `[text](url)`.
82
+ - **Images** are added via `![alternative text](path)`.
83
+
84
+ ---
85
+
86
+ ### Installation
87
+ To get started, run the following command in your terminal:
88
+ `pip install markrender`
89
+
90
+ ### Feature Comparison
91
+ | Feature | Syntax |
92
+ | :--- | :--- |
93
+ | Bold | **text** |
94
+ | Italic | *text* |
95
+ | Inline Code | `code` |
96
+
97
+ > **Note:** Ensure your renderer is finalized after use to prevent memory leaks.
98
+ """
99
+
100
+ renderer.render(markdown_text)
101
+ renderer.finalize()
102
+ ```
103
+
104
+ How to render streaming api responses
105
+
106
+ ```python
107
+ from openai import OpenAI
108
+
109
+ renderer = MarkdownRenderer(theme='github-dark', line_numbers=True)
110
+
111
+ API_KEY = # Your openai api key
112
+
113
+ client = OpenAI(api_key=API_KEY)
114
+
115
+ stream = client.chat.completions.create(
116
+ model="openai/gpt-oss-120b",
117
+ messages=[
118
+ {
119
+ "role": "system",
120
+ "content": "You are a highly capable AI assistant that answers clearly and concisely."
121
+ },
122
+ {
123
+ "role": "user",
124
+ "content": "Whats the difference between C and C++?"
125
+ }
126
+ ],
127
+ stream=True
128
+ )
129
+ for chunk in stream:
130
+ data = chunk.choices[0].delta.content
131
+ if data:
132
+ renderer.render(data)
133
+
134
+ renderer.finalize()
135
+ ```
136
+
137
+ ## 🎨 Advanced Configuration
138
+
139
+ You can customize the renderer's appearance and behavior with the following parameters:
140
+
141
+ ```python
142
+ from markrender import MarkdownRenderer
143
+
144
+ renderer = MarkdownRenderer(
145
+ theme='monokai', # Set the color style
146
+ line_numbers=True, # Show numbers next to code lines
147
+ code_background=True, # Add a background color to code blocks
148
+ force_color=True, # Always show colors
149
+ stream_code=True # Render code blocks line-by-line
150
+ )
151
+ ```
152
+
153
+ ### Non-Streaming Code Blocks
154
+
155
+ If you prefer to render code blocks all at once after the entire block has been received, you can set `stream_code=False`. This is useful if you want to avoid seeing incomplete code blocks during streaming.
156
+
157
+ ```python
158
+ renderer = MarkdownRenderer(stream_code=False)
159
+ ```
160
+
161
+ ## Available themes
162
+
163
+ * github-dark
164
+ * monokai
165
+ * dracula
166
+ * nord
167
+ * one-dark
168
+ * solarized-dark
169
+ * solarized-light
170
+
171
+
172
+ ---
173
+
174
+ ## 📊 Table Rendering Excellence
175
+
176
+ MarkRender provides robust table rendering powered by the `rich` library. Tables are beautifully formatted with proper alignment, borders, and theme-appropriate colors. The renderer handles streaming edge cases gracefully, ensuring tables render correctly even when content arrives in chunks.
177
+
178
+ ## 🤝 Contributing
179
+
180
+ We welcome contributions! Feel free to open issues or pull requests on our [GitHub repository](https://github.com/Praneeth-Gandodi/markrender).
181
+
182
+ ## 📄 License
183
+
184
+ MarkRender is released under the MIT License. See the [LICENSE](LICENSE) file for more details.
@@ -0,0 +1,152 @@
1
+ # MarkRender 🎨
2
+
3
+ **A professional terminal markdown renderer built for streaming LLM responses.**
4
+
5
+ MarkRender is a Python library designed to bring beautifully rendered markdown directly to your terminal. It's especially good for displaying streaming output from large language models, ensuring a smooth, flicker-free experience with rich formatting and syntax highlighting.
6
+
7
+ ## ✨ Features You'll Love
8
+
9
+ * **Streaming Optimized**: Renders markdown chunks as they arrive, perfect for LLM interactions.
10
+ * **Gorgeous Themes**: Comes with several built-in color themes to match your terminal aesthetic.
11
+ * **Smart Syntax Highlighting**: Powered by Pygments, it makes your code blocks pop.
12
+ * **Full Markdown Support**: Handles everything from headings and lists to tables, checkboxes, emojis, and links with robust streaming support.
13
+ * **Cross-Platform**: Works on Windows, macOS, and Linux.
14
+
15
+ ## 🚀 Get Started
16
+
17
+ ### Installation
18
+
19
+ It's super easy to get MarkRender up and running:
20
+
21
+ ```bash
22
+ pip install git+https://github.com/Praneeth-Gandodi/markrender.git
23
+ ```
24
+
25
+ Or, for development, clone the repository and install in editable mode:
26
+ ```bash
27
+ git clone https://github.com/Praneeth-Gandodi/markrender.git
28
+ cd markrender
29
+ pip install -e .
30
+ ```
31
+
32
+ ### Quick Usage
33
+
34
+ Here's how to render a simple markdown string
35
+
36
+ ```python
37
+ from markrender import MarkdownRenderer
38
+
39
+ renderer = MarkdownRenderer()
40
+
41
+ markdown_text = """
42
+ # Project Title
43
+ This is a comprehensive markdown example that demonstrates various features.
44
+ It includes headers, lists, links, images, and code blocks.
45
+
46
+ ## Subsection Explanation
47
+ - **Headers** are defined using `#` symbols.
48
+ - **Lists** can be ordered or unordered.
49
+ - **Links** use the syntax: `[text](url)`.
50
+ - **Images** are added via `![alternative text](path)`.
51
+
52
+ ---
53
+
54
+ ### Installation
55
+ To get started, run the following command in your terminal:
56
+ `pip install markrender`
57
+
58
+ ### Feature Comparison
59
+ | Feature | Syntax |
60
+ | :--- | :--- |
61
+ | Bold | **text** |
62
+ | Italic | *text* |
63
+ | Inline Code | `code` |
64
+
65
+ > **Note:** Ensure your renderer is finalized after use to prevent memory leaks.
66
+ """
67
+
68
+ renderer.render(markdown_text)
69
+ renderer.finalize()
70
+ ```
71
+
72
+ How to render streaming api responses
73
+
74
+ ```python
75
+ from openai import OpenAI
76
+
77
+ renderer = MarkdownRenderer(theme='github-dark', line_numbers=True)
78
+
79
+ API_KEY = # Your openai api key
80
+
81
+ client = OpenAI(api_key=API_KEY)
82
+
83
+ stream = client.chat.completions.create(
84
+ model="openai/gpt-oss-120b",
85
+ messages=[
86
+ {
87
+ "role": "system",
88
+ "content": "You are a highly capable AI assistant that answers clearly and concisely."
89
+ },
90
+ {
91
+ "role": "user",
92
+ "content": "Whats the difference between C and C++?"
93
+ }
94
+ ],
95
+ stream=True
96
+ )
97
+ for chunk in stream:
98
+ data = chunk.choices[0].delta.content
99
+ if data:
100
+ renderer.render(data)
101
+
102
+ renderer.finalize()
103
+ ```
104
+
105
+ ## 🎨 Advanced Configuration
106
+
107
+ You can customize the renderer's appearance and behavior with the following parameters:
108
+
109
+ ```python
110
+ from markrender import MarkdownRenderer
111
+
112
+ renderer = MarkdownRenderer(
113
+ theme='monokai', # Set the color style
114
+ line_numbers=True, # Show numbers next to code lines
115
+ code_background=True, # Add a background color to code blocks
116
+ force_color=True, # Always show colors
117
+ stream_code=True # Render code blocks line-by-line
118
+ )
119
+ ```
120
+
121
+ ### Non-Streaming Code Blocks
122
+
123
+ If you prefer to render code blocks all at once after the entire block has been received, you can set `stream_code=False`. This is useful if you want to avoid seeing incomplete code blocks during streaming.
124
+
125
+ ```python
126
+ renderer = MarkdownRenderer(stream_code=False)
127
+ ```
128
+
129
+ ## Available themes
130
+
131
+ * github-dark
132
+ * monokai
133
+ * dracula
134
+ * nord
135
+ * one-dark
136
+ * solarized-dark
137
+ * solarized-light
138
+
139
+
140
+ ---
141
+
142
+ ## 📊 Table Rendering Excellence
143
+
144
+ MarkRender provides robust table rendering powered by the `rich` library. Tables are beautifully formatted with proper alignment, borders, and theme-appropriate colors. The renderer handles streaming edge cases gracefully, ensuring tables render correctly even when content arrives in chunks.
145
+
146
+ ## 🤝 Contributing
147
+
148
+ We welcome contributions! Feel free to open issues or pull requests on our [GitHub repository](https://github.com/Praneeth-Gandodi/markrender).
149
+
150
+ ## 📄 License
151
+
152
+ MarkRender is released under the MIT License. See the [LICENSE](LICENSE) file for more details.
@@ -0,0 +1,30 @@
1
+
2
+ from pygments import highlight
3
+ from pygments.lexers import PythonLexer
4
+ from pygments.formatters import Terminal256Formatter, TerminalTrueColorFormatter
5
+ from rich.text import Text
6
+ from rich.console import Console
7
+
8
+ code = "def hello():\n print('world')"
9
+ lexer = PythonLexer()
10
+
11
+ print("--- Terminal256Formatter ---")
12
+ formatter256 = Terminal256Formatter(style='monokai')
13
+ ansi256 = highlight(code, lexer, formatter256)
14
+ rich_text256 = Text.from_ansi(ansi256)
15
+ print(f"ANSI len: {len(ansi256)}")
16
+ print(f"First span style: {rich_text256.spans[0] if rich_text256.spans else 'None'}")
17
+
18
+ print("\n--- TerminalTrueColorFormatter ---")
19
+ formatterTC = TerminalTrueColorFormatter(style='monokai')
20
+ ansiTC = highlight(code, lexer, formatterTC)
21
+ rich_textTC = Text.from_ansi(ansiTC)
22
+ print(f"ANSI len: {len(ansiTC)}")
23
+ print(f"First span style: {rich_textTC.spans[0] if rich_textTC.spans else 'None'}")
24
+
25
+ print("\n--- Visual Check ---")
26
+ console = Console()
27
+ console.print("256:")
28
+ console.print(rich_text256)
29
+ console.print("TrueColor:")
30
+ console.print(rich_textTC)
@@ -0,0 +1,76 @@
1
+ """
2
+ Basic usage example for MarkRender
3
+ Demonstrates rendering static markdown content
4
+ """
5
+
6
+ from markrender import MarkdownRenderer
7
+
8
+
9
+ def main():
10
+ """Basic markdown rendering example"""
11
+
12
+ # Create renderer with default theme
13
+ renderer = MarkdownRenderer(theme='github-dark')
14
+
15
+ # Sample markdown content
16
+ markdown = """
17
+ # MarkRender Demo
18
+
19
+ Welcome to **MarkRender** - a professional terminal markdown renderer!
20
+
21
+ ## Features
22
+
23
+ Here are some key features:
24
+
25
+ - 🎨 Beautiful syntax highlighting
26
+ - 📊 Table rendering
27
+ - ✅ Task lists
28
+ - 😊 Emoji support
29
+ - And much more!
30
+
31
+ ## Code Example
32
+
33
+ ```python
34
+ from markrender import MarkdownRenderer
35
+
36
+ renderer = MarkdownRenderer()
37
+ renderer.render("# Hello World")
38
+ renderer.finalize()
39
+ ```
40
+
41
+ ## Task List
42
+
43
+ - [x] Install MarkRender
44
+ - [x] Read documentation
45
+ - [ ] Build something awesome!
46
+
47
+ ## Table Example
48
+
49
+ | Feature | Status |
50
+ |---------|--------|
51
+ | Headings | ✓ |
52
+ | Code Blocks | ✓ |
53
+ | Tables | ✓ |
54
+
55
+ ## Links and Formatting
56
+
57
+ Visit [GitHub](https://github.com) for more info.
58
+
59
+ Use `inline code` for short snippets.
60
+
61
+ > This is a blockquote.
62
+ > It can span multiple lines!
63
+
64
+ ---
65
+
66
+ Made with ❤️ using MarkRender
67
+ """
68
+
69
+ # Render the markdown
70
+ print("Rendering markdown content...\n")
71
+ renderer.render(markdown)
72
+ renderer.finalize()
73
+
74
+
75
+ if __name__ == '__main__':
76
+ main()
@@ -0,0 +1,134 @@
1
+ """
2
+ Streaming demo for MarkRender
3
+ Simulates LLM streaming response
4
+ """
5
+
6
+ import time
7
+ from markrender import MarkdownRenderer
8
+
9
+
10
+ def simulate_streaming():
11
+ """Simulate streaming LLM response"""
12
+
13
+ # Simulated markdown response chunks
14
+ response = """
15
+ # Quantum Computing Explained
16
+
17
+ Quantum computing is a revolutionary technology that leverages the principles of **quantum mechanics** to process information.
18
+
19
+ ## Key Concepts
20
+
21
+ ### 1. Qubits
22
+
23
+ Unlike classical bits that can only be 0 or 1, **qubits** can exist in a *superposition* of both states simultaneously.
24
+
25
+ ```python
26
+ # Classical bit
27
+ bit = 0 # or 1
28
+
29
+ # Qubit (conceptual)
30
+ qubit = alpha|0⟩ + beta|1⟩
31
+ ```
32
+
33
+ ### 2. Superposition
34
+
35
+ Superposition allows quantum computers to:
36
+ - Process multiple possibilities at once
37
+ - Explore solution spaces exponentially faster
38
+ - Solve certain problems classical computers cannot
39
+
40
+ ### 3. Entanglement
41
+
42
+ When qubits become entangled:
43
+ - [x] Their states become correlated
44
+ - [x] Measuring one affects the other
45
+ - [x] Distance doesn't matter
46
+
47
+ ## Comparison Table
48
+
49
+ | Aspect | Classical | Quantum |
50
+ |--------|-----------|---------|
51
+ | Basic unit | Bit (0 or 1) | Qubit (superposition) |
52
+ | Gates | AND, OR, NOT | Hadamard, CNOT, etc. |
53
+ | Speed | Linear | Exponential (for some problems) |
54
+
55
+ ## Applications
56
+
57
+ > Quantum computing promises to revolutionize fields like cryptography, drug discovery, and optimization problems.
58
+
59
+ Some exciting applications include:
60
+
61
+ 1. **Cryptography** - Breaking current encryption :lock:
62
+ 2. **Drug Discovery** - Simulating molecular interactions :pill:
63
+ 3. **Optimization** - Solving complex logistics problems :package:
64
+ 4. **AI/ML** - Accelerating machine learning :robot:
65
+
66
+ ## Example Algorithm
67
+
68
+ ```python
69
+ from qiskit import QuantumCircuit
70
+
71
+ # Create a quantum circuit
72
+ qc = QuantumCircuit(2, 2)
73
+
74
+ # Apply Hadamard gate
75
+ qc.h(0)
76
+
77
+ # Apply CNOT gate
78
+ qc.cx(0, 1)
79
+
80
+ # Measure
81
+ qc.measure([0, 1], [0, 1])
82
+ ```
83
+
84
+ ### Challenges
85
+
86
+ Current quantum computers face several challenges:
87
+
88
+ - **Decoherence** - Qubits lose their quantum state quickly
89
+ - **Error rates** - High error rates require error correction
90
+ - **Scalability** - Building large-scale quantum computers is difficult
91
+
92
+ ---
93
+
94
+ *For more information, visit [IBM Quantum](https://www.ibm.com/quantum)*
95
+
96
+ Hope this helps! :wave:
97
+ """
98
+
99
+ # Split into chunks (simulating streaming)
100
+ chunk_size = 10 # characters per chunk
101
+ for i in range(0, len(response), chunk_size):
102
+ chunk = response[i:i + chunk_size]
103
+ yield chunk
104
+ time.sleep(0.01) # Simulate network delay
105
+
106
+
107
+ def main():
108
+ """Streaming markdown rendering demo"""
109
+
110
+ print("Simulating streaming LLM response...\n")
111
+ print("=" * 80)
112
+ print()
113
+
114
+ # Create renderer
115
+ renderer = MarkdownRenderer(
116
+ theme='github-dark',
117
+ code_background=False,
118
+ line_numbers=True
119
+ )
120
+
121
+ # Render streaming chunks
122
+ for chunk in simulate_streaming():
123
+ renderer.render(chunk)
124
+
125
+ # Finalize rendering
126
+ renderer.finalize()
127
+
128
+ print()
129
+ print("=" * 80)
130
+ print("\n\nStreaming complete! ✓")
131
+
132
+
133
+ if __name__ == '__main__':
134
+ main()