quarto-dev / quarto-dev/quarto-cli

Adaptive syntax highlighting themes do not apply code block background colour

Open
#14,090 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

accessibility bug code-blocks themes
Dominant language
JavaScript
Stars
6k
Forks
458
Avg merge
1d 9h
Merged PRs (30d)
41

Description

Bug description

When using an adaptive syntax highlighting theme name (e.g., syntax-highlighting: github), the code block background colour defined in the resolved .theme file is not applied. The $code-block-bg SCSS variable is never set, so code blocks inherit the Bootstrap theme's default background instead of the highlighting theme's background.

Using the explicit variant name (syntax-highlighting: github-light or syntax-highlighting: github-dark) works correctly because those names are not in the isAdaptiveTheme() list.

This means adaptive themes that define a background-color or editor-colors.BackgroundColor in their .theme files are effectively not supported: the background is silently discarded. This also breaks accessibility for those themes because the token colours were designed for a specific background colour to meet contrast requirements. When the background is discarded and replaced by an arbitrary Bootstrap theme background, the contrast ratios between syntax tokens and the code block background are no longer guaranteed, potentially failing WCAG guidelines.

7 out of 8 adaptive themes are affected:

Adaptive theme Light variant background Dark variant background
a11y #fefefe #2b2b2b
arrow #f1f3f5 (none)
atom-one (none) (none)
ayu #fafafa #0a0e14
breeze #ffffff #232629
github #ffffff #24292e
gruvbox #fbf1c7 #282828
monochrome #ffffff #000000

Only atom-one is unaffected (neither variant defines a background). arrow is partially affected (light variant has a background, dark does not).

Root cause

In src/format/html/format-html-scss.ts, the resolveTextHighlightingLayer() function guards background colour injection with !themeDescriptor.isAdaptive:

if (themeDescriptor && !themeDescriptor.isAdaptive) {
  const backgroundColor = () => { /* ... */ };
  const background = backgroundColor();
  if (background) {
    layer.defaults = outputVariable(
      sassVariable("code-block-bg", asCssColor(background)),
      true,
    );
  }
  // ...
}

This guard was introduced in commit f6d26305c ("Explicit adaptive theme block support").

The theme file resolution in readHighlightingTheme() already correctly resolves the style-specific variant (e.g., github-light.theme for light mode, github-dark.theme for dark mode). Both files define background colours (editor-colors.BackgroundColor = #ffffff and background-color = #24292e respectively), but the !isAdaptive guard prevents those values from being used.

Steps to reproduce

Render the following three documents and compare the code block backgrounds in both light and dark mode:

  • Document 1: Adaptive theme (github)
---
format:
  html:
    theme:
      light: flatly
      dark: cosmo
    syntax-highlighting: github
---

```r
print("Hello, Quarto!")
```
  • Document 2: Explicit light variant (github-light)
---
format:
  html:
    theme:
      light: flatly
      dark: cosmo
    syntax-highlighting: github-light
---

```r
print("Hello, Quarto!")
```
  • Document 3: Explicit dark variant (github-dark)
---
format:
  html:
    theme:
      light: flatly
      dark: cosmo
    syntax-highlighting: github-dark
---

```r
print("Hello, Quarto!")
```
Actual behavior
  • Document 1 (github): code block background comes from the Bootstrap theme (flatly/cosmo), not from the github theme files.
  • Document 2 (github-light): code block background is #ffffff (from github-light.theme).
  • Document 3 (github-dark): code block background is #24292e (from github-dark.theme).

In light mode, Document 1 and Document 2 should look identical but do not (different code block background).
In dark mode, Document 1 and Document 3 should look identical but do not (different code block background).

The generated CSS for the adaptive theme (github) has no background-color on div.sourceCode, while the explicit variants do.

Expected behavior

syntax-highlighting: github should produce the same visual result as syntax-highlighting: github-light in light mode and syntax-highlighting: github-dark in dark mode, including the code block background colour.

Since resolveTextHighlightingLayer() is called separately for each style ("light" and "dark"), and readHighlightingTheme() already resolves the correct variant for each style, the $code-block-bg SCSS variable should be set from the resolved theme file regardless of whether the theme is adaptive.

Your environment
  • IDE: VS Code
  • OS: macOS 26.3
Quarto check output
Quarto 99.9.9
[✓] Checking environment information...
      Quarto cache location: /Users/mcanouil/Library/Caches/quarto
[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.8.3: OK
      Dart Sass version 1.87.0: OK
      Deno version 2.4.5: OK
      Typst version 0.14.2: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 99.9.9
      commit: 6ecfc030bfcf381a37a925612b78e95876dcece2
      Path: /Users/mcanouil/Projects/quarto-dev/quarto-cli/package/dist/bin
[✓] Checking tools....................OK
      TinyTeX: v2026.02
[✓] Checking LaTeX....................OK
      Using: TinyTex
      Path: /Users/mcanouil/Library/TinyTeX/bin/universal-darwin
      Version: 2025
[✓] Checking basic markdown render....OK
[✓] Checking R installation...........OK
      Version: 4.5.2
      Path: /Library/Frameworks/R.framework/Resources
      knitr: 1.50
      rmarkdown: 2.30
[✓] Checking Knitr engine render......OK
[✓] Checking Python 3 installation....OK
      Version: 3.14.0
      Jupyter: 5.9.1
      Kernels: python3
[✓] Checking Jupyter engine render....OK

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/format/html/format-html-scss.ts at resolveTextHighlightingLayer(), then trace how readHighlightingTheme() resolves light and dark adaptive variants. Render the three provided documents and compare their code block CSS; done means adaptive github matches github-light and github-dark in the corresponding modes, including the background colour.

Written by the indexing model from the issue text.

Assessment

Tech stack
bootstrap, sass, typescript
Domain
frontend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.