feat: Allow customizing emphasis and bold text colors via html_theme_options#356
feat: Allow customizing emphasis and bold text colors via html_theme_options#356
Conversation
…options Add four new theme options to customize emphasis (em) and definition (strong/b) text colors for both light and dark modes: - emphasis_color: Color for em tags in light mode (default: #2d9f42) - emphasis_color_dark: Color for em tags in dark mode (default: #66bb6a) - definition_color: Color for strong/b tags in light mode (default: #8b4513) - definition_color_dark: Color for strong/b tags in dark mode (default: #cd853f) Implementation approach: - Replace hardcoded SCSS colors with CSS custom properties (var()) with fallback values matching the original defaults - Register new options in theme.conf with empty defaults - Inject custom property overrides via inline style in layout.html when theme options are set This is fully backward-compatible: existing sites see no visual change. When options are left empty, CSS var() fallbacks provide the original colors. Closes #355
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #356 +/- ##
=======================================
Coverage ? 46.48%
=======================================
Files ? 2
Lines ? 398
Branches ? 0
=======================================
Hits ? 185
Misses ? 213
Partials ? 0
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
🎭 Visual Regression Test ResultsDetails
Skipped testsmobile-chrome › theme.spec.ts › Theme Features › f-string interpolation styling |
The option applies to all <strong>/<b> elements, not just definitions. Sphinx renders actual definitions via <dl>/<dt> elements which can be targeted separately. Renamed across SCSS, theme.conf, layout.html, tests, and documentation.
Add definition_color and definition_color_dark theme options that target actual Sphinx definition list elements (dl.simple dt, dl.glossary dt, dl.field-list dt) separately from strong/bold text. The definition color falls back to the strong color via CSS variable chain: var(--qe-definition-color, var(--qe-strong-color, fallback)), so definitions inherit from strong_color by default but can be independently customized.
Add 5 Playwright visual tests in a new 'Typography Styling' describe block: - bold text styling (light mode) - italic text styling (light mode) - mixed bold and italic styling - bold text in dark mode - italic text in dark mode Uses .qe-page__content selectors to target paragraphs containing <strong> and <em> elements on names.html, numpy.html, and python_by_example.html. Note: definition list (<dl>) tests not included as the lecture site does not currently contain definition lists.
|
/update-new-snapshots |
1 similar comment
|
/update-new-snapshots |
|
✅ Visual snapshots have been updated and committed to this PR. |
There was a problem hiding this comment.
Pull request overview
This pull request implements a feature to allow customization of emphasis (italic), bold/strong, and definition text colors through html_theme_options, resolving issue #355. The implementation uses CSS custom properties with graceful fallbacks to SCSS-defined default colors, allowing users to override text styling colors without needing custom CSS files.
Changes:
- Added six new theme options (
emphasis_color,emphasis_color_dark,strong_color,strong_color_dark,definition_color,definition_color_dark) for customizing text colors in light and dark modes - Implemented CSS variable injection in
layout.htmlto apply user-specified colors via:rootandbody.dark-themeselectors - Updated SCSS files (
_base.scssand_dark-theme.scss) to use CSS custom properties with fallback values for backward compatibility - Added comprehensive test coverage (40 tests) covering theme configuration, SCSS variables, compiled CSS, and template injection
- Added visual regression tests for typography styling in both light and dark modes
- Updated documentation with usage examples for both Sphinx and Jupyter Book configurations
- Enhanced developer documentation (
.github/copilot-instructions.md) with GitHub CLI best practices
Reviewed changes
Copilot reviewed 8 out of 16 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/quantecon_book_theme/theme/quantecon_book_theme/theme.conf |
Registers six new color customization options with empty defaults |
src/quantecon_book_theme/theme/quantecon_book_theme/layout.html |
Conditionally injects CSS custom property overrides when theme options are set |
src/quantecon_book_theme/assets/styles/_base.scss |
Updates em, strong/b, and dl dt selectors to use CSS variables with SCSS fallbacks |
src/quantecon_book_theme/assets/styles/_dark-theme.scss |
Updates dark mode colors to use CSS variables with fallbacks |
tests/test_custom_colors.py |
Adds 40 tests verifying theme options, SCSS variables, compiled CSS, and template injection |
tests/visual/theme.spec.ts |
Adds visual regression tests for bold and italic text in light and dark modes |
tests/visual/__snapshots__/**/*.png |
Visual test baseline snapshots for typography styling |
docs/configure.md |
Documents the new color customization options with usage examples and reference table |
.github/copilot-instructions.md |
Adds GitHub CLI best practices for avoiding shell escaping issues |
- Validate color theme options against safe CSS patterns (hex, named colors, rgb/hsl functions) at build time - Invalid values are ignored with a warning logged - Add 14 tests for validation regex (valid and malicious patterns) - Add security note to documentation Addresses Copilot code review feedback on PR #356.
Addressing Copilot Review FeedbackThanks for the review. Both comments have been addressed in commit f77e6a1: 1. CSS Injection Vulnerability (layout.html)Rather than the suggested
Invalid values (e.g. 2. Security Note in Documentation (configure.md)Added a TestsAdded 14 new tests in |
Summary
Resolves #355 — Allow customizing emphasis, bold/strong, and definition text colors via
html_theme_options.Adds six new theme options that let users override the default colors for emphasis (italic), bold/strong, and definition list terms in both light and dark modes, using CSS custom properties with graceful fallbacks.
New Theme Options
emphasis_coloremtags in light mode#2d9f42(green)emphasis_color_darkemtags in dark mode#66bb6a(light green)strong_colorstrong/btags in light mode#8b4513(brown)strong_color_darkstrong/btags in dark mode#cd853f(peru)definition_colordl dt) in light modestrong_colordefinition_color_darkdl dt) in dark modestrong_color_darkUsage
Sphinx
conf.py:Jupyter Book
_config.yml:Any option left empty uses the theme's built-in default. The
definition_coloroptions target Sphinx definition lists (dl.simple,dl.glossary,dl.field-list), whilestrong_colorapplies to all inlinestrong/btext. Definitions fall back to the strong color by default via CSS variable chain.Implementation
--qe-emphasis-color,--qe-strong-color,--qe-definition-color) with SCSS fallback values in_base.scssand_dark-theme.scsstheme.conf(all default to empty)layout.htmlconditionally injects<style>block with CSS variable overrides on:rootandbody.dark-themeconfigure.mdwith usage examples, Jupyter Book config, and option reference tableTesting
All 40 custom color tests pass, plus existing test suite (65 total tests pass).