Skip to content

Commit e19cef3

Browse files
committed
test - add test for changing highlighting for dark and light
1 parent bfa8274 commit e19cef3

File tree

2 files changed

+72
-2
lines changed

2 files changed

+72
-2
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
format:
3+
html:
4+
highlight-style:
5+
light: pygments
6+
dark: kate
7+
---
8+
9+
## Light and Dark Mode Testing
10+
11+
This document can be viewed in both light mode and dark mode to test code highlighting in both color schemes.
12+
13+
```{.julia}
14+
function divide_floats(x::Float64, y::Float64)
15+
return x / y
16+
end
17+
```
18+
19+
And here the inline version `function divide_floats(x::Float64, y::Float64)`{.julia}.
20+
21+
::: {.callout-note}
22+
The tests will automatically check the highlighting in both light and dark modes using Playwright's color scheme testing capabilities.
23+
:::

tests/integration/playwright/tests/html-code-highlight.spec.ts

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,36 @@ const highlightStyles = [
2626
'solarized',
2727
'tango',
2828
'vim-dark',
29-
'zenburn'
29+
'zenburn',
30+
// specific alias for light-dark test
31+
'light-dark'
3032
];
3133

3234
const colorSchemes: Array<'light' | 'dark'> = ['light', 'dark'];
3335

36+
37+
// This is a special case for light-dark theme
38+
// We test pygments and kate themes so we retrieve the colors from the themeConfig
39+
// in src\resources\pandoc\highlight-styles\*.theme
40+
const themeConfigLightDark = {
41+
light: {
42+
name: 'pygments',
43+
colors: {
44+
kw: '#007020',
45+
fu: '#06287e'
46+
}
47+
},
48+
dark: {
49+
name: 'kate',
50+
colors: {
51+
kw: '#1f1c1b',
52+
fu: '#644a9b'
53+
}
54+
}
55+
};
56+
3457
for (const style of highlightStyles) {
35-
test.describe(`Code highlighting for ${style} theme`, () => {
58+
test.describe(`Code highlighting for '${style}' theme`, () => {
3659

3760
for (const colorScheme of colorSchemes) {
3861
test.describe(`in ${colorScheme} mode`, () => {
@@ -62,6 +85,30 @@ for (const style of highlightStyles) {
6285

6386
await checkColor(codeBlock, 'color', hexToRgb(keywordColor));
6487
});
88+
if (style === 'light-dark') {
89+
const themeUsed = themeConfigLightDark[colorScheme].name;
90+
const colorUsed = themeConfigLightDark[colorScheme].colors;
91+
test(`[${style}] Code highlighting for Inline and CodeBlock are using '${themeUsed}' theme`, async ({ page }) => {
92+
const funName = page.locator('div pre.sourceCode code.julia span').getByText('function');
93+
const divideFloats = page.locator('div pre.sourceCode code.julia span').getByText('divide_floats');
94+
// Get specific syntax elements to test for color
95+
// get the class on the span
96+
const classNameFun = await funName.getAttribute('class') as string;
97+
const classNameDivide = await divideFloats.getAttribute('class') as string;
98+
// error if not found
99+
if (!classNameFun || !classNameDivide) {
100+
test.fail(true, 'Class name not found for code highlighting elements');
101+
}
102+
const funColor = colorUsed[classNameFun];
103+
const divideColor = colorUsed[classNameDivide];
104+
await checkColor(funName, 'color', hexToRgb(funColor));
105+
await checkColor(divideFloats, 'color', hexToRgb(divideColor));
106+
// check also root variable
107+
await checkColor(page.locator('body'), `--quarto-hl-${classNameFun}-color`, funColor);
108+
await checkColor(page.locator('body'), `--quarto-hl-${classNameDivide}-color`, divideColor);
109+
});
110+
}
111+
65112
});
66113
}
67114
});

0 commit comments

Comments
 (0)