-
-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bug: color is missing if I print a diff with rich.syntax #43
Comments
Hey @15r10nk, thanks for the report! Interesting. My first intuition is that Rich uses ANSI codes that are not supported by pygments-ansi. I'll replicate the issue locally and report back 🙂 |
Unfortunately none of the available color systems improve the situation 😕 I really thought the I don't know Rich enough to understand what it does with ANSI codes. I think its Workaround: # codi.py
import os
from rich.console import Console
from rich.syntax import Syntax
console=Console(color_system="256")
code = """
code
- a
+ b
"""
with open(os.devnull, "w") as devnull:
console = Console(record=True, width=65, file=devnull, markup=False)
renderable = Syntax(code, "diff", theme="material")
console.print(renderable, markup=True, highlight=False)
print(console.export_html(inline_styles=True, code_format="<pre><code>{code}</code></pre>")) <!-- index.md -->
```python exec="1" html="1"
--8<-- "codi.py"
``` |
Here's the ANSI output of Rich with 256 color mode:
I've manually escaped the escape sequence ( |
Here it is with the standard color mode:
|
It's a bit better with this (works for console = Console(color_system="standard")
code = """
code
- a
+ b
"""
console.print(Syntax(code, "diff", theme="ansi_light")) |
Aha! This translates as a |
For some reason, pygments-ansi-color sometimes output `-Color-BrightRed` CSS classes instead of `-Color-Bold-Red`. These class weren't declared so spans with these classes were unstyled. We fix this by adding such classes for each color. Issue-43: #43
Should be fixed in v1.8.1. Try with the standard color system and the ansi_light/ansi_dark theme and let me know if there are any other issues 🙂 |
Thank you, it works for me now. |
Description of the bug
I use markdown-exec to include the output of pytest in my documentation.
I use rich to generate some diffs during this run and have the problem that the red and green colors are missing in the diff.
I was able to reproduce this bug without pytest, but I have no idea if this is a markdown-exec or rich problem.
Can you please look into?
To Reproduce
see the repository
Expected behavior
I would expect that markdown-exec is able to produce the same colors which I also see in the terminal.
Environment information
python -m markdown_exec.debug # | xclip -selection clipboard
markdown-exec
v1.8.0Additional context
The text was updated successfully, but these errors were encountered: