Skip to content

Commit 8c557cf

Browse files
default background and foreground for inline code in dark mode
fixes #8568 this minimal and defensive change (found and iterated with Claude) changes inline code without .sourceCode to use the same default background and foreground colors as the block code, when in dark mode. it is probably more defensive than it needs to be it also causes code with .sourceCode to default to the code block background if not otherwise specified, instead of $grey-100, in both modes.
1 parent a7360e1 commit 8c557cf

File tree

6 files changed

+56
-20
lines changed

6 files changed

+56
-20
lines changed

news/changelog-1.8.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ All changes included in 1.8:
2020
- ([#726](https://github.com/quarto-dev/quarto-cli/issues/726)): a11y - Provide `.screen-reader-only` callout type when callout text doesn't naturally include the type.
2121
- ([#5538](https://github.com/quarto-dev/quarto-cli/issues/5538)): Fix code-copy button style so that scrolling behaves properly.
2222
- ([#5879](https://github.com/quarto-dev/quarto-cli/issues/5879)): Improve font rendering of `kbd` shortcode on macOS. `kbd` will now also be stricter in converting keyboard shortcuts to macOS icons.
23+
- ([#8568](https://github.com/quarto-dev/quarto-cli/issues/8568)) Default inline code background color to the code block background color if not specified; foreground color is `$pre-color` in dark mode and (remains) purple in light mode.
2324
- ([#10983](https://github.com/quarto-dev/quarto-cli/issues/10983)): Fix spacing inconsistency between paras and first section headings.
2425
- ([#12259](https://github.com/quarto-dev/quarto-cli/issues/12259)): Fix conflict between `html-math-method: katex` and crossref popups (author: @benkeks).
2526
- ([#12341](https://github.com/quarto-dev/quarto-cli/issues/12341)): Enable light and dark logos for html formats (sidebar, navbar, dashboard).
@@ -108,7 +109,7 @@ All changes included in 1.8:
108109

109110
- ([#12753](https://github.com/quarto-dev/quarto-cli/issues/12753)): Support change in IPython 9+ and import `set_matplotlib_formats` from `matplotlib_inline.backend_inline` in the internal `setup.py` script used to initialize rendering with Jupyter engine.
110111
- ([#12839](https://github.com/quarto-dev/quarto-cli/issues/12839)): Support for `plotly.py` 6+ which now loads plotly.js using a cdn in script as a module.
111-
- ([#13026](https://github.com/quarto-dev/quarto-cli/pulls/13026), [#13151](https://github.com/quarto-dev/quarto-cli/pulls/13151)), [#13184](https://github.com/quarto-dev/quarto-cli/pull/13184): Use `jsdelivr` CDN for jupyter widgets dependencies.
112+
- ([#13026](https://github.com/quarto-dev/quarto-cli/pull/13026), [#13151](https://github.com/quarto-dev/quarto-cli/pull/13151)), [#13184](https://github.com/quarto-dev/quarto-cli/pull/13184): Use `jsdelivr` CDN for jupyter widgets dependencies.
112113

113114
### `knitr`
114115

src/resources/formats/html/bootstrap/_bootstrap-rules.scss

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,26 @@ pre {
923923
border: initial;
924924
}
925925

926+
p code.sourceCode,
927+
li code.sourceCode,
928+
td code.sourceCode {
929+
$calculated-bg: if(
930+
variable-exists(code-bg),
931+
if(
932+
$code-bg == $gray-100 and variable-exists(code-block-bg-color),
933+
$code-block-bg-color,
934+
$code-bg
935+
),
936+
null
937+
);
938+
939+
@if variable-exists(mono-background-color) {
940+
background-color: $mono-background-color;
941+
} @else if variable-exists(calculated-bg) {
942+
background-color: $calculated-bg;
943+
}
944+
}
945+
926946
// Maps the pandoc 'monobackgroundcolor' to bootstrap
927947
// Note this only targets code outside of sourceCode blocks
928948
@if variable-exists(mono-background-color) {
@@ -942,14 +962,23 @@ pre code:not(.sourceCode) {
942962
background-color: initial;
943963
}
944964

945-
// Default padding if background is set
946965
p code:not(.sourceCode),
947966
li code:not(.sourceCode),
948967
td code:not(.sourceCode) {
968+
$calculated-bg: if(
969+
variable-exists(code-bg),
970+
if(
971+
$code-bg == $gray-100 and variable-exists(code-block-bg-color),
972+
$code-block-bg-color,
973+
$code-bg
974+
),
975+
null
976+
);
977+
949978
@if variable-exists(mono-background-color) {
950979
background-color: $mono-background-color;
951-
} @else if variable-exists(code-bg) {
952-
background-color: $code-bg;
980+
} @else if variable-exists(calculated-bg) {
981+
background-color: $calculated-bg;
953982
}
954983

955984
@if variable-exists(code-padding) {
@@ -2197,12 +2226,12 @@ a {
21972226

21982227
// screen-reader-only, cf https://github.com/quarto-dev/quarto-cli/issues/726#issuecomment-1112486100
21992228
.screen-reader-only {
2200-
position: absolute;
2201-
clip: rect(0 0 0 0);
2202-
border: 0;
2203-
height: 1px;
2204-
margin: -1px;
2205-
overflow: hidden;
2206-
padding: 0;
2207-
width: 1px;
2208-
}
2229+
position: absolute;
2230+
clip: rect(0 0 0 0);
2231+
border: 0;
2232+
height: 1px;
2233+
margin: -1px;
2234+
overflow: hidden;
2235+
padding: 0;
2236+
width: 1px;
2237+
}

src/resources/formats/html/bootstrap/_bootstrap-variables.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ $code-block-theme-dark-threshhold: 40% !default;
3838

3939
/* Inline Code Formatting */
4040
// $code-bg, $code-color, $code-padding
41-
$code-color: #7d12ba !default;
41+
$code-color: if(
42+
variable-exists(pre-color) and $pre-color != null,
43+
$pre-color,
44+
#7d12ba
45+
) !default;
4246

4347
// Set a default body emphasis color
4448
$code-bg: $gray-100 !default;

tests/docs/playwright/html/dark-brand/syntax-highlighting/a11y-syntax-highlighting.qmd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ execute:
55
warning: false
66
theme:
77
light: [cosmo, theme.scss]
8-
dark: [cosmo, theme-dark.scss]
8+
dark: [solar, theme-dark.scss]
99
highlight-style: a11y
1010
---
1111

1212
### Inline code
1313

14+
* No syntax highlighting: `foo(bar)`
1415
* Python: `def identity(x): return x`{.python}
1516
* R: `identity <- function(x) x`{.r}
1617

tests/docs/playwright/html/dark-brand/syntax-highlighting/arrow-syntax-highlighting.qmd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ _quarto:
1414

1515
### Inline code
1616

17+
* No syntax highlighting: `foo(bar)`
1718
* Python: `def identity(x): return x`{.python}
1819
* R: `identity <- function(x) x`{.r}
1920

tests/integration/playwright/tests/html-dark-mode.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ test('Syntax highlighting, a11y, with JS', async ({ page }) => {
4545
const importKeyword = await page.locator('span.im').first();
4646
// light inline code
4747
const pythonCode = await page.locator('li code.sourceCode.r');
48-
await expect(pythonCode).toHaveCSS('background-color', 'rgb(248, 249, 250)');
48+
await expect(pythonCode).toHaveCSS('background-color', 'rgba(233, 236, 239, 0.65)');
4949
await expect(pythonCode).toHaveCSS('color', 'rgb(125, 18, 186)');
5050
// light highlight stylesheet
5151
await expect(importKeyword).toHaveCSS('color', 'rgb(84, 84, 84)');
5252

5353
await page.locator("a.quarto-color-scheme-toggle").click();
5454

5555
// dark inline code
56-
await expect(pythonCode).toHaveCSS('background-color', 'rgb(248, 249, 250)');
56+
await expect(pythonCode).toHaveCSS('background-color', 'rgba(0, 0, 0, 0)');
5757
await expect(pythonCode).toHaveCSS('color', 'rgb(192, 128, 216)');
5858
// dark highlight stylesheet
5959
await expect(importKeyword).toHaveCSS('color', 'rgb(248, 248, 242)');
@@ -69,14 +69,14 @@ test('Syntax highlighting, arrow, with JS', async ({ page }) => {
6969
await expect(locatr).toHaveCSS('background-color', 'rgb(255, 255, 255)');
7070
// light inline code
7171
const pythonCode = await page.locator('li code.sourceCode.python');
72-
await expect(pythonCode).toHaveCSS('background-color', 'rgb(248, 249, 250)');
72+
await expect(pythonCode).toHaveCSS('background-color', 'rgba(233, 236, 239, 0.65)');
7373
await expect(pythonCode).toHaveCSS('color', 'rgb(125, 18, 186)');
7474
// alert
7575
const link = await page.locator('span.al').first();
7676
await expect(link).toHaveCSS('background-color', 'rgba(0, 0, 0, 0)'); // transparent
7777

7878
await page.locator("a.quarto-color-scheme-toggle").click();
7979
// dark inline code
80-
await expect(pythonCode).toHaveCSS('background-color', 'rgb(248, 249, 250)');
81-
await expect(pythonCode).toHaveCSS('color', 'rgb(125, 18, 186)');
80+
await expect(pythonCode).toHaveCSS('background-color', 'rgba(37, 41, 46, 0.65)');
81+
await expect(pythonCode).toHaveCSS('color', 'rgb(122, 130, 136)');
8282
});

0 commit comments

Comments
 (0)