Download src/sr_harness/utils/render_python.py from YuMeow/SRHarness: direct link, hf CLI and curl.
- Browser
- Download file 600 Bytes
-
https://huggingface.co/spaces/YuMeow/SRHarness/resolve/main/src/sr_harness/utils/render_python.py
- Command line
-
hf download hf://spaces/YuMeow/SRHarness/src/sr_harness/utils/render_python.py
-
curl -L -o render_python.py https://huggingface.co/spaces/YuMeow/SRHarness/resolve/main/src/sr_harness/utils/render_python.py
600 Bytes
| # Copyright (c) 2024-present, Yumeow. Licensed under the MIT License. | |
| from rich.console import Console | |
| from rich.markdown import Markdown | |
| from rich.syntax import Syntax | |
| def render_python(text: str, width=120, highlight_lines=[], theme="staroffice") -> str: | |
| console = Console(record=True, width=width) | |
| with console.capture() as capture: | |
| code = Syntax( | |
| text, | |
| "python", | |
| theme=theme, | |
| word_wrap=True, | |
| line_numbers=True, | |
| highlight_lines=highlight_lines, | |
| ) | |
| console.print(code) | |
| return capture.get() | |