-
Notifications
You must be signed in to change notification settings - Fork 142
Update fenced code block color legibility #2816
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: master
Are you sure you want to change the base?
Conversation
Highlight styles are too dark to be legible, and they don't account for dark/light code block themes. Let's * Use CSS variables for highlighter styles * Update site page processing to set data-code-theme on body based on site config * Add in CSS rules that set a suitable highlight colour in the variables based on the data-code-theme
Due to new data-code-theme attribute on body, html output is different. This requires us to update the test script built output to match the expected value.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2816 +/- ##
=======================================
Coverage 71.85% 71.85%
=======================================
Files 134 134
Lines 7340 7340
Branches 1565 1623 +58
=======================================
Hits 5274 5274
- Misses 1938 2020 +82
+ Partials 128 46 -82 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Change made for easy viewing:
is the light grey supposed to be white instead? @Harjun751 |
|
I will update the wording, thanks for flagging that. |
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.
Pull request overview
This PR updates the fenced code block highlighting colors to improve legibility across MarkBind's built-in code themes. The implementation changes the color shorthand system from hardcoded CSS color names to CSS variables that adapt based on the selected code theme.
Changes:
- Modified color mappings in HighlightRule.ts to use CSS variables (e.g.,
var(--red)) instead of hardcoded color names - Added theme-specific CSS variable definitions for light and dark code themes in markbind.css
- Injected
data-code-themeattribute into the body tag via the Nunjucks template to enable theme-aware styling - Updated documentation to show color swatches and descriptions for both light and dark themes
- Updated functional test expected outputs to reflect the new body tag attribute
Reviewed changes
Copilot reviewed 115 out of 116 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/core/src/lib/markdown-it/highlight/HighlightRule.ts | Changed color mappings from hardcoded strings to CSS variable references |
| packages/core-web/src/styles/markbind.css | Added CSS variable definitions for 8 colors in both light and dark theme variants |
| packages/core/src/Page/page.njk | Added data-code-theme attribute to body tag for theme-aware CSS selection |
| packages/core/src/Page/index.ts | Passed codeTheme from siteConfig to template context |
| packages/core/test/unit/lib/markdown-it/highlight/HighlightRule.test.ts | Updated test expectations to reflect CSS variable usage |
| packages/core/test/unit/utils/data.ts | Updated mock template with trailing space (incomplete update) |
| docs/userGuide/syntax/code.md | Enhanced documentation with visual color swatches and theme-specific descriptions |
| packages/cli/test/functional/.../expected/*.html (70+ files) | Updated expected HTML outputs with data-code-theme="light" or "dark" attributes |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /** Light code theme variables **/ | ||
| [data-code-theme="light"] { | ||
| --red: rgb(255 121 115 / 40%); | ||
| --green: rgb(0 255 0 / 70%); | ||
| --blue: rgb(124 153 255 / 50%); | ||
| --cyan: rgb(0 255 255 / 60%); | ||
| --magenta: rgb(255 100 255 / 70%); | ||
| --yellow: rgb(255 255 0 / 70%); | ||
| --black: rgb(217 217 217 / 100%); | ||
| --white: rgb(255 255 255 / 100%); | ||
| } | ||
|
|
||
| /** Dark code theme variables **/ | ||
| [data-code-theme="dark"] { | ||
| --red: rgb(176 13 19 / 70%); | ||
| --green: rgb(5 102 0 / 70%); | ||
| --blue: rgb(2 38 255 / 70%); | ||
| --cyan: rgb(0 150 150 / 70%); | ||
| --magenta: rgb(139 0 139 / 100%); | ||
| --yellow: rgb(150 140 0 / 70%); | ||
| --black: rgb(0 0 0 / 100%); | ||
| --white: rgb(150 150 150 / 50%); | ||
| } |
Copilot
AI
Feb 2, 2026
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.
The CSS variable definitions for the highlight colors lack fallback values. If an element is rendered before the CSS is loaded, or if the data-code-theme attribute is missing or has an invalid value, the CSS variables will be undefined, causing the highlights to not render with any background color. Consider adding default variable definitions in the :root selector as fallbacks.
| {% endif %} | ||
| </head> | ||
| <body> | ||
| <body > |
Copilot
AI
Feb 2, 2026
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.
The PAGE_NJK_LITERAL mock template should be updated to match the actual page.njk template structure. The trailing space after 'body' appears incomplete and doesn't include the new data-code-theme attribute that was added to the actual template in page.njk. While this mock is simplified, it should still reflect the key structural changes for consistency in testing.
| k | <span style="display:inline-block; width:20px; height:20px; background:rgb(217 217 217 / 100%); border-radius:3px; margin-right:5px;"></span> Dark black | <span style="display:inline-block; width:20px; height:20px; background:rgb(0 0 0 / 100%); border-radius:3px; margin-right:5px;"></span> Pure black | ||
| w | <span style="display:inline-block; width:20px; height:20px; background:rgb(255 255 255 / 100%); border-radius:3px; margin-right:5px;"></span> Light grey | <span style="display:inline-block; width:20px; height:20px; background:rgb(150 150 150 / 50%); border-radius:3px; margin-right:5px;"></span> Silver grey |
Copilot
AI
Feb 2, 2026
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.
The color descriptions for 'k' (black) and 'w' (white) in the Light Theme column appear to be inconsistent with the actual CSS color values. The CSS defines --black as rgb(217 217 217 / 100%) which is a light gray, but the documentation describes it as "Dark black". Similarly, --white is defined as rgb(255 255 255 / 100%) which is pure white, but the documentation describes it as "Light grey". The descriptions should match the actual rendered colors for clarity.
| k | <span style="display:inline-block; width:20px; height:20px; background:rgb(217 217 217 / 100%); border-radius:3px; margin-right:5px;"></span> Dark black | <span style="display:inline-block; width:20px; height:20px; background:rgb(0 0 0 / 100%); border-radius:3px; margin-right:5px;"></span> Pure black | |
| w | <span style="display:inline-block; width:20px; height:20px; background:rgb(255 255 255 / 100%); border-radius:3px; margin-right:5px;"></span> Light grey | <span style="display:inline-block; width:20px; height:20px; background:rgb(150 150 150 / 50%); border-radius:3px; margin-right:5px;"></span> Silver grey | |
| k | <span style="display:inline-block; width:20px; height:20px; background:rgb(217 217 217 / 100%); border-radius:3px; margin-right:5px;"></span> Light grey | <span style="display:inline-block; width:20px; height:20px; background:rgb(0 0 0 / 100%); border-radius:3px; margin-right:5px;"></span> Pure black | |
| w | <span style="display:inline-block; width:20px; height:20px; background:rgb(255 255 255 / 100%); border-radius:3px; margin-right:5px;"></span> Pure white | <span style="display:inline-block; width:20px; height:20px; background:rgb(150 150 150 / 50%); border-radius:3px; margin-right:5px;"></span> Silver grey |
| --magenta: rgb(255 100 255 / 70%); | ||
| --yellow: rgb(255 255 0 / 70%); | ||
| --black: rgb(217 217 217 / 100%); | ||
| --white: rgb(255 255 255 / 100%); |
Copilot
AI
Feb 2, 2026
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.
The 'w' (white) color for the light theme is defined as pure white rgb(255 255 255 / 100%), which may have insufficient contrast when used as a highlight background color against the typical light-colored code block backgrounds. Consider using a slightly darker or more saturated color that maintains visibility while still being distinct from the black/gray option.

What is the purpose of this pull request?
Resolves #2800
Overview of changes:
Updates current code highlighting shorthands to use predefined CSS variables. The variables are set to colors that maintain legibility in two of the respective code themes in markbind. How specific colors are selected is by using an attribute-selector that looks for the data-code-theme value that is set in the body.
The data-code-theme is set by using the site.json values and injecting into the nunjucks template, much like the various other settings.
Anything you'd like to highlight/discuss:
The large amount of files changed is due to the body tag having the data-code-theme attribute set, meaning that many of the functional tests' "expected" files had to change.
You can see how the colours look in the linked issue above.
Testing instructions:
Proposed commit message: (wrap lines at 72 characters)
Update highlighter styles for legibility
Checklist: ☑️
Reviewer checklist:
Indicate the SEMVER impact of the PR:
At the end of the review, please label the PR with the appropriate label:
r.Major,r.Minor,r.Patch.Breaking change release note preparation (if applicable):