Skip to content

fix(monaco): support high contrast themes in shikiToMonaco#1185

Open
Yashsingh045 wants to merge 2 commits intoshikijs:mainfrom
Yashsingh045:fix/shiki-to-monaco-high-contrast
Open

fix(monaco): support high contrast themes in shikiToMonaco#1185
Yashsingh045 wants to merge 2 commits intoshikijs:mainfrom
Yashsingh045:fix/shiki-to-monaco-high-contrast

Conversation

@Yashsingh045
Copy link
Copy Markdown

Description

This PR adds support for high-contrast themes in shikiToMonaco.

Previously, shikiToMonaco would assign vs or vs-dark as the base theme based on the theme type (light or dark). This caused issues with high-contrast themes (like GitHub High Contrast) where the selection foreground color would not be visible because Monaco only applies editor.selectionForeground when the base theme is hc-black or hc-light.

I have added a new themes option to ShikiToMonacoOptions that allows users to explicitly specify the theme type, including hc and hc-light.

Fixes #1081

Changes

  • Updated ShikiToMonacoOptions to include a themes property for overrides.
  • Updated textmateThemeToMonacoTheme to accept an options object and determine the correct base theme (hc-black, hc-light, vs, or vs-dark) based on the configuration.
  • Updated shikiToMonaco to pass these options down.

Verification

  • Added a reproduction test case in packages/monaco/test/high-contrast.test.ts which verifies that providing the hc type correctly sets the base theme to hc-black.
  • Verified that existing tests in packages/monaco/test/repro.test.ts still pass.

Usage Example

shikiToMonaco(highlighter, monaco, {
  themes: {
    'github-dark-high-contrast': {
      type: 'hc' // Sets base to 'hc-black'
    }
  }
})

@netlify
Copy link
Copy Markdown

netlify bot commented Dec 3, 2025

Deploy Preview for shiki-next ready!

Name Link
🔨 Latest commit 742a9e0
🔍 Latest deploy log https://app.netlify.com/projects/shiki-next/deploys/693013a4951cc10008b75289
😎 Deploy Preview https://deploy-preview-1185--shiki-next.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link
Copy Markdown

netlify bot commented Dec 3, 2025

Deploy Preview for shiki-matsu ready!

Name Link
🔨 Latest commit 742a9e0
🔍 Latest deploy log https://app.netlify.com/projects/shiki-matsu/deploys/693013a4951cc10008b75287
😎 Deploy Preview https://deploy-preview-1185--shiki-matsu.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@codecov
Copy link
Copy Markdown

codecov bot commented Dec 3, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.20%. Comparing base (61c87e8) to head (742a9e0).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1185   +/-   ##
=======================================
  Coverage   95.20%   95.20%           
=======================================
  Files          92       92           
  Lines        7922     7922           
  Branches     1689     1689           
=======================================
  Hits         7542     7542           
  Misses        374      374           
  Partials        6        6           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@antfu
Copy link
Copy Markdown
Member

antfu commented Dec 3, 2025

I wonder if #1099 would be easier and simple. Do you see any other cases that need more customizations?

@Yashsingh045
Copy link
Copy Markdown
Author

hey @antfu ,

I checked #1099. The auto-detection based on theme name is definitely simpler for the common ‘happy path’, but relying only on string matching can be limiting for more advanced setups.

For example, any high-contrast theme that doesn’t follow the exact naming convention — such as my-accessible-theme or company-contrast-theme — wouldn’t be recognized correctly. Since #1099 doesn’t provide an override mechanism, users would have no way to handle these cases.

My PR #1185 introduces a themes option that acts as an explicit escape hatch. It lets users define high-contrast behavior for any theme, not just the ones that match predefined naming patterns. This keeps shikiToMonaco simple for typical use cases while still offering flexibility for custom or non-standard themes.

@Yashsingh045
Copy link
Copy Markdown
Author

Yashsingh045 commented Dec 3, 2025

Hi @antfu ,
Just checking in — please let me know if there’s anything more I should address in this PR.
A review when possible would be greatly appreciated.

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 this pull request may close these issues.

shikiToMonaco needs to take into account high-contrast themes

2 participants