Skip to content

Conversation

@prempyla
Copy link

@prempyla prempyla commented Nov 7, 2025

…gh) (#1022)

Description

This PR fixes an issue where shikiToMonaco failed to preserve Markdown text styles (bold, italic, strikethrough) when integrating Shiki themes into the Monaco Editor.
Previously, Monaco tokens were mapped only by color, which caused loss of font-style metadata.
Now, styles like bold, italic, and strikethrough are correctly rendered across all supported themes.

Summary of Changes

  • Added normalizeFontStyleString() and normalizeFontStyleBits() to handle Shiki → Monaco font style mapping.

  • Implemented dual mapping for:

    • color → scope (backward compatibility)
    • color + style → scope (for accurate style preservation)
  • Updated textmateThemeToMonacoTheme() to forward fontStyle correctly.

  • Simplified theme registration logic and removed redundant mappings.

  • Verified behavior for Markdown tokens (markup.bold, markup.italic, markup.strikethrough).


Linked Issue

Fixes #1022


Testing & Verification

  • Env: [email protected], Shiki themes github-dark / github-light.

  • API Check:

    editor._themeService._knownThemes.get('github-dark').tokenTheme._match('markup.bold')
    // → _fontStyle: 2 (bold)
  • Result:
    Bold, italic, and strikethrough now render correctly; no regressions found.

  • Console:

    Style applied: markup.bold bold
    Style applied: markup.italic italic
    Style applied: markup.strikethrough strikethrough
    

Additional context

Verified theme switching (github-dark ↔ github-light) works correctly.

No regressions observed in syntax highlighting for other languages.

The change aligns Monaco’s highlighting fidelity with Shiki’s output.

@netlify
Copy link

netlify bot commented Nov 7, 2025

Deploy Preview for shiki-next ready!

Name Link
🔨 Latest commit 4b9a1c7
🔍 Latest deploy log https://app.netlify.com/projects/shiki-next/deploys/690e1d6552145e0008368100
😎 Deploy Preview https://deploy-preview-1107--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

netlify bot commented Nov 7, 2025

Deploy Preview for shiki-matsu ready!

Name Link
🔨 Latest commit 4b9a1c7
🔍 Latest deploy log https://app.netlify.com/projects/shiki-matsu/deploys/690e1d65a5e3720008dc6302
😎 Deploy Preview https://deploy-preview-1107--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

codecov bot commented Nov 7, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.35%. Comparing base (5068b26) to head (4b9a1c7).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1107   +/-   ##
=======================================
  Coverage   88.35%   88.35%           
=======================================
  Files          74       74           
  Lines        3322     3322           
  Branches      956      954    -2     
=======================================
  Hits         2935     2935           
  Misses        344      344           
  Partials       43       43           

☔ 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.


const colorMap: string[] = []
const colorToScopeMap = new Map<string, string>()
const colorAndStyleToScopeMap = new Map<string, string>()
Copy link
Member

Choose a reason for hiding this comment

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

Can we have these two maps together? When FontStyle is none, we just do color, for the key, and when it is present, we do color|font-style?

Copy link
Author

Choose a reason for hiding this comment

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

yes @antfu ,Merged into a single colorStyleToScopeMap using color or color|font-style as key — simpler and avoids duplication.

Comment on lines +207 to +209
styles.delete('')
styles.delete('normal')
styles.delete('none')
Copy link
Member

Choose a reason for hiding this comment

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

What are those?

Copy link
Author

@prempyla prempyla Nov 7, 2025

Choose a reason for hiding this comment

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

@antfu These lines remove redundant or default style tokens ('', normal, none) that can appear in some themes.
They don’t affect valid styles but keep normalization consistent.
I can remove them if you prefer.

token: s,
foreground: normalizeColor(foreground),
background: normalizeColor(background),
fontStyle,
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should normalize the fontStyle here? And I think we can do a simple alphabet sorting.

Copy link
Author

Choose a reason for hiding this comment

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

@antfu Done-Normalized and alphabetically sorted fontStyle in textmateThemeToMonacoTheme() for consistent comparison.

@prempyla
Copy link
Author

Hi @antfu , just checking in , I’ve made the requested changes and pushed the updates.
Please take a look when you get a chance. Thanks again for your time and feedback!

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 doesn't preserve bold, italics, and more in Markdown

2 participants