Skip to content

Commit c902253

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 ff8e1f8 commit c902253

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

src/command/render/pandoc-html.ts

Lines changed: 22 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,12 @@ 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+
const lightDep = extras.html?.[kDependencies]?.find((extraDep) =>
312+
extraDep.name === kQuartoHtmlDependency
313+
);
314+
const lightEntry = lightDep?.stylesheets &&
315+
lightDep.stylesheets[lightDep.stylesheets.length - 1];
322316
extras = await resolveQuartoSyntaxHighlighting(
323317
inputDir,
324318
extras,
@@ -327,6 +321,19 @@ export async function resolveSassBundles(
327321
"dark",
328322
defaultStyle,
329323
);
324+
if (defaultStyle === "light") {
325+
const dep2 = extras.html?.[kDependencies]?.find((extraDep) =>
326+
extraDep.name === kQuartoHtmlDependency
327+
);
328+
assert(dep2?.stylesheets && lightEntry);
329+
dep2.stylesheets.push({
330+
...lightEntry,
331+
attribs: {
332+
...lightEntry.attribs,
333+
class: "quarto-color-scheme-extra",
334+
},
335+
});
336+
}
330337
}
331338

332339
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)