-
-
Notifications
You must be signed in to change notification settings - Fork 487
fix(monaco): preserve Markdown font styles (bold, italic, strikethrou… #1107
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
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for shiki-next ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for shiki-matsu ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
packages/monaco/src/index.ts
Outdated
|
|
||
| const colorMap: string[] = [] | ||
| const colorToScopeMap = new Map<string, string>() | ||
| const colorAndStyleToScopeMap = new Map<string, string>() |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
| styles.delete('') | ||
| styles.delete('normal') | ||
| styles.delete('none') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are those?
There was a problem hiding this comment.
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.
packages/monaco/src/index.ts
Outdated
| token: s, | ||
| foreground: normalizeColor(foreground), | ||
| background: normalizeColor(background), | ||
| fontStyle, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
Hi @antfu , just checking in , I’ve made the requested changes and pushed the updates. |
…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()andnormalizeFontStyleBits()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 forwardfontStylecorrectly.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 themesgithub-dark/github-light.API Check:
Result:
Bold, italic, and
strikethroughnow render correctly; no regressions found.Console:
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.