Skip to content

Commit 14bfdef

Browse files
committed
Improve highlight-style resolving
We would previously start by treating the `highlight-style` value as a path and seeing whether it exists, then if it did, treating it like a theme path. By default the `highlight-style` value is `arrow`, so a folder named `arrow` sitting next to a QMD would cause this issue :(. Instead, first try to resolve it as a built in theme, then search the file system if it doesn’t resolve! Fixes #3739
1 parent 50ff271 commit 14bfdef

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/command/render/pandoc-html.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ export function generateCssKeyValues(textValues: Record<string, unknown>) {
498498
if (textValues[textAttr]) {
499499
lines.push("font-style: italic;");
500500
} else {
501-
lines.push("font-style: inherit");
501+
lines.push("font-style: inherit;");
502502
}
503503
break;
504504
case "underline":

src/quarto-core/text-highlighting.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { FormatPandoc } from "../config/types.ts";
1313
import { existsSync } from "fs/mod.ts";
1414
import { resourcePath } from "../core/resources.ts";
1515
import { normalizePath } from "../core/path.ts";
16-
import { error } from "log/mod.ts";
1716
import { warnOnce } from "../core/log.ts";
1817

1918
export interface ThemeDescriptor {
@@ -40,11 +39,6 @@ export function textHighlightThemePath(
4039
resolvedTheme = theme as string;
4140
}
4241

43-
const userThemePath = join(inputDir, resolvedTheme);
44-
if (existsSync(userThemePath)) {
45-
return normalizePath(userThemePath);
46-
}
47-
4842
// First try the style specific version of the theme, otherwise
4943
// fall back to the plain name
5044
const names = [
@@ -55,7 +49,20 @@ export function textHighlightThemePath(
5549
const themePath = names.map((name) => {
5650
return resourcePath(join("pandoc", "highlight-styles", `${name}.theme`));
5751
}).find((path) => existsSync(path));
58-
return themePath;
52+
53+
if (themePath) {
54+
// first see if this matches a built in name
55+
return themePath;
56+
} else {
57+
// see if this is a path to a user theme
58+
const userThemePath = join(inputDir, resolvedTheme);
59+
if (existsSync(userThemePath)) {
60+
return normalizePath(userThemePath);
61+
}
62+
}
63+
64+
// Could find a path
65+
return undefined;
5966
}
6067

6168
export function readHighlightingTheme(

0 commit comments

Comments
 (0)