Skip to content
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

Code blocks are rendered in bright white #249

Closed
kurtmckee opened this issue Dec 4, 2024 · 6 comments · Fixed by #251
Closed

Code blocks are rendered in bright white #249

kurtmckee opened this issue Dec 4, 2024 · 6 comments · Fixed by #251

Comments

@kurtmckee
Copy link
Contributor

Hello! I'm creating a repo-review plugin and wanted to include a Markdown code block in the error results. However, the output renders very harshly in the terminal and is not visually accessible (note that the hyphens are not visible due to the colors in use):

image

The .check() string that produced this includes this Markdown code:

```yaml
- repo: "meta"
  hooks:
    - id: "check-hooks-apply"
    - id: "check-useless-excludes"
```

I don't think this is related to my plugin, but rather the default syntax highlighting used in the repo-review framework.

@henryiii
Copy link
Collaborator

henryiii commented Dec 13, 2024

I think we can't detect the terminal color scheme, and Rich forces you to pick a fixed pigments theme for code blocks, so I picked the light one because I thought it was more readable. Unless that changes, we are kind of stuck. You'd need to covert a Pygments color theme (256 fixed colors) into the 16 terminal settable colors. https://rich.readthedocs.io/en/stable/syntax.html#theme

We set "default" as the code theme. We don't set "default" as the background, as then it would be black on black at times, I think. But maybe we should verify?

@henryiii
Copy link
Collaborator

henryiii commented Dec 13, 2024

From my little test, it looks like ansi_light and ansi_dark might both do exactly the same thing and work?

#!/usr/bin/env uv run --quiet

# /// script
# dependencies = ["rich"]
# ///

import sys

from rich.console import Console
from rich.markdown import Markdown
from rich.syntax import Syntax


THEME = sys.argv[1]
MARKDOWN = """
# This is an h1

Rich can do a pretty *decent* job of rendering markdown.

1. This is a list item
2. This is another list item

```python
from rich.console import Console
from rich.markdown import Markdown

def f():
    return 42
```

```yaml
- repo: "meta"
  hooks:
    - id: "check-hooks-apply"
    - id: "check-useless-excludes"
```
"""

console = Console()
md = Markdown(MARKDOWN, code_theme=THEME)
console.print(md)

@kurtmckee
Copy link
Contributor Author

ansi_light and ansi_dark are similar -- though not identical -- and both resolve the inaccessible code block rendering reported here.

Switching back and forth between the renderings in two tabs, I have a preference for ansi_light, which appears just slightly more vibrant as rendered in my terminal. Would you be open to PR to switch to this theme?


ansi_light

image

ansi_dark

image


kurtmckee added a commit to kurtmckee/pr-repo-review that referenced this issue Dec 13, 2024
This eliminates a bright white background color
that renders for Markdown code blocks.

This change was tested on light and dark terminal backgrounds
and does not force a background color in either case.

Fixes scientific-python#249
@henryiii
Copy link
Collaborator

Released 0.11.3 with the fix, thanks!

@henryiii
Copy link
Collaborator

(also added a similar fix to https://github.com/scikit-hep/uproot-browser when it gives example code ;) )

@kurtmckee
Copy link
Contributor Author

Nice! Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants