Skip to content

fix(shell): prevent Rich default markdown styles from leaking background colors#1739

Merged
RealKai42 merged 1 commit intomainfrom
kaiyi/la-paz
Apr 3, 2026
Merged

fix(shell): prevent Rich default markdown styles from leaking background colors#1739
RealKai42 merged 1 commit intomainfrom
kaiyi/la-paz

Conversation

@RealKai42
Copy link
Copy Markdown
Collaborator

@RealKai42 RealKai42 commented Apr 3, 2026

Summary

  • Override all Rich default markdown.* styles to "none" in NEUTRAL_MARKDOWN_THEME to prevent background color leakage (e.g., black backgrounds on inline code and code blocks)
  • Add regression tests ensuring no markdown.* style carries a background color
  • The core fix targets markdown.code ("bold cyan on black") and markdown.code_block ("cyan on black"); additional keys (markdown.emph, markdown.h7, markdown.list) are overridden as a defensive measure

Test plan

  • New unit tests verify markdown.code and markdown.code_block have no bgcolor
  • Generic guard test ensures all markdown.* styles have no bgcolor
  • Full test suite passes (2024 passed, 0 failed)
  • Manual verification: render Markdown with inline code and fenced code blocks on light/dark terminals

Closes #1681


Open with Devin

…ckground color leakage

NEUTRAL_MARKDOWN_THEME inherits from Rich's defaults via inherit=True.
Rich's built-in "markdown.code" and "markdown.code_block" styles include
"on black" backgrounds that leak through on non-black terminals. Override
all Rich markdown.* style keys to "none" so the custom _FALLBACK_STYLES
control the final appearance.

Closes #1681
Copilot AI review requested due to automatic review settings April 3, 2026 06:02
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the shell’s Rich theme configuration to avoid Rich’s default Markdown styles introducing unintended background colors (notably for inline code and code blocks), and adds regression tests plus release-note entries documenting the fix.

Changes:

  • Extend NEUTRAL_MARKDOWN_THEME to explicitly neutralize additional markdown.* styles (including markdown.code / markdown.code_block) to prevent inherited “on black” backgrounds.
  • Add unit tests asserting markdown.code / markdown.code_block have no background color and attempting to guard against future markdown.* background leakage.
  • Add Unreleased changelog entries (EN/ZH + root) documenting the rendering fix.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/kimi_cli/ui/shell/console.py Adds more markdown.* theme overrides to prevent Rich default Markdown backgrounds from leaking into shell rendering.
tests/ui/test_console_theme.py Adds regression tests asserting the theme’s Markdown-related styles don’t set a background color.
CHANGELOG.md Adds an Unreleased entry describing the Markdown black-background fix.
docs/en/release-notes/changelog.md Mirrors the Unreleased changelog note in English docs.
docs/zh/release-notes/changelog.md Mirrors the Unreleased changelog note in Chinese docs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +49 to +53
for name, style in NEUTRAL_MARKDOWN_THEME.styles.items():
if name.startswith("markdown."):
assert style.bgcolor is None, (
f"{name} should have no background color, got bgcolor={style.bgcolor}"
)
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test_all_markdown_styles_have_no_background() only iterates over NEUTRAL_MARKDOWN_THEME.styles, which contains only explicitly-defined overrides. This won’t catch cases where a markdown.* key is missing and a background color is inherited from Rich’s defaults (the main failure mode described in the docstring). Consider enumerating the markdown style names you rely on (e.g., from kimi_cli.utils.rich.markdown._FALLBACK_STYLES and any other markdown.* names used via markup) and asserting Console(theme=NEUTRAL_MARKDOWN_THEME).get_style(name).bgcolor is None for each, so missing overrides fail the test.

Copilot uses AI. Check for mistakes.
Comment on lines 13 to 17
"markdown.paragraph": "none",
"markdown.block_quote": "none",
"markdown.hr": "none",
"markdown.list": "none",
"markdown.item": "none",
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The newly added overrides markdown.list, markdown.h7, and markdown.emph don’t appear to be referenced anywhere else in the codebase (search only finds them in this theme). If they’re intended purely as a defensive override against Rich internals, it would help to add a brief comment explaining why these keys are needed here; otherwise consider dropping unused keys to keep the theme definition aligned with actual style names we render.

Copilot uses AI. Check for mistakes.
@RealKai42 RealKai42 merged commit 73b0ef2 into main Apr 3, 2026
24 checks passed
@RealKai42 RealKai42 deleted the kaiyi/la-paz branch April 3, 2026 06:25
Yuandiaodiaodiao added a commit to Yuandiaodiaodiao/kimi-cli that referenced this pull request Apr 3, 2026
…und colors (MoonshotAI#1739)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants