Skip to content

Commit 31e496f

Browse files
order highlight stylesheets light, dark or light, dark, light
this fixes the light syntax highlighting being applied in dark mdoe since we are no longer disabling the light stylesheet use the same light, dark, light pattern as the main stylesheet
1 parent 6737842 commit 31e496f

File tree

2 files changed

+27
-16
lines changed

2 files changed

+27
-16
lines changed

src/command/render/pandoc-html.ts

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -295,19 +295,9 @@ export async function resolveSassBundles(
295295
}
296296
}
297297

298-
// Resolve generated quarto css variables
299-
if (hasDarkStyles && defaultStyle !== "dark") {
300-
// Put dark stylesheet first if light is default (for NoJS)
301-
extras = await resolveQuartoSyntaxHighlighting(
302-
inputDir,
303-
extras,
304-
format,
305-
project,
306-
"dark",
307-
defaultStyle,
308-
);
309-
}
310-
298+
// light only: light
299+
// author prefers dark: light, dark
300+
// author prefers light: light, dark, light
311301
extras = await resolveQuartoSyntaxHighlighting(
312302
inputDir,
313303
extras,
@@ -317,8 +307,15 @@ export async function resolveSassBundles(
317307
defaultStyle,
318308
);
319309

320-
if (hasDarkStyles && defaultStyle === "dark") {
321-
// Put dark stylesheet second if dark is default (for NoJS)
310+
if (hasDarkStyles) {
311+
// find the last entry, for the light highlight stylesheet
312+
// so we can duplicate it below.
313+
// (note we must do this before adding the dark highlight stylesheet)
314+
const lightDep = extras.html?.[kDependencies]?.find((extraDep) =>
315+
extraDep.name === kQuartoHtmlDependency
316+
);
317+
const lightEntry = lightDep?.stylesheets &&
318+
lightDep.stylesheets[lightDep.stylesheets.length - 1];
322319
extras = await resolveQuartoSyntaxHighlighting(
323320
inputDir,
324321
extras,
@@ -327,6 +324,19 @@ export async function resolveSassBundles(
327324
"dark",
328325
defaultStyle,
329326
);
327+
if (defaultStyle === "light") {
328+
const dep2 = extras.html?.[kDependencies]?.find((extraDep) =>
329+
extraDep.name === kQuartoHtmlDependency
330+
);
331+
assert(dep2?.stylesheets && lightEntry);
332+
dep2.stylesheets.push({
333+
...lightEntry,
334+
attribs: {
335+
...lightEntry.attribs,
336+
class: "quarto-color-scheme-extra",
337+
},
338+
});
339+
}
330340
}
331341

332342
if (isHtmlOutput(format.pandoc, true)) {

src/resources/formats/html/templates/quarto-html-before-body.ejs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@
172172
<% } %>
173173
174174
<% if (!darkModeDefault) { %>
175-
document.querySelector('link.quarto-color-scheme-extra').rel = 'disabled-stylesheet';
175+
document.querySelector('link#quarto-text-highlighting-styles.quarto-color-scheme-extra').rel = 'disabled-stylesheet';
176+
document.querySelector('link#quarto-bootstrap.quarto-color-scheme-extra').rel = 'disabled-stylesheet';
176177
<% } %>
177178
178179
let localAlternateSentinel = darkModeDefault ? 'alternate' : 'default';

0 commit comments

Comments
 (0)