Skip to content

Commit 4020f9c

Browse files
committed
html: move theme: pandoc print styles after the base rules
Pandoc 3.13's styles.html places its @media print block before the a, blockquote, code and pre rules. Media queries add no specificity, so the later screen rules win when printing: a linkcolor survives print, blockquotes stay grey, and monobackgroundcolor keeps its background and padding. Moving the block to the end of the document-css section lets the print resets apply as intended. Pandoc's own template has the same ordering; this is a local divergence until it is fixed upstream. Adds a Playwright test that emulates print media on a theme: pandoc document with linkcolor and monobackgroundcolor set.
1 parent dd67d98 commit 4020f9c

3 files changed

Lines changed: 57 additions & 21 deletions

File tree

‎src/resources/formats/html/pandoc/styles.html‎

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,6 @@
3636
font-size: 1.8em;
3737
}
3838
}
39-
@media print {
40-
html {
41-
color-scheme: light only;
42-
}
43-
html, body, pre, code {
44-
background-color: transparent;
45-
}
46-
body, a, a:visited, blockquote {
47-
color: black;
48-
}
49-
pre, code {
50-
padding: 0;
51-
}
52-
p, h2, h3 {
53-
orphans: 3;
54-
widows: 3;
55-
}
56-
h2, h3, h4 {
57-
page-break-after: avoid;
58-
}
59-
}
6039
p {
6140
margin: 1em 0;
6241
}
@@ -191,6 +170,29 @@
191170
#TOC a:not(:hover) {
192171
text-decoration: none;
193172
}
173+
/* quarto-specific: print block placed after the base rules so its resets
174+
win over linkcolor, blockquote and monobackgroundcolor styles */
175+
@media print {
176+
html {
177+
color-scheme: light only;
178+
}
179+
html, body, pre, code {
180+
background-color: transparent;
181+
}
182+
body, a, a:visited, blockquote {
183+
color: black;
184+
}
185+
pre, code {
186+
padding: 0;
187+
}
188+
p, h2, h3 {
189+
orphans: 3;
190+
widows: 3;
191+
}
192+
h2, h3, h4 {
193+
page-break-after: avoid;
194+
}
195+
}
194196
$endif$
195197
span.smallcaps{font-variant: small-caps;}
196198
div.columns{display: flex; gap: 1.5em;}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
title: theme pandoc print styles
3+
format:
4+
html:
5+
theme: pandoc
6+
linkcolor: "#ff0000"
7+
monobackgroundcolor: "#eeeeee"
8+
---
9+
10+
A [link](https://quarto.org) and `inline code`.
11+
12+
> A blockquote.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { test, expect } from "@playwright/test";
2+
import { getUrl } from "../src/utils";
3+
4+
// theme: pandoc renders Pandoc's styles.html. Its print block must win over
5+
// the screen colors set by linkcolor and monobackgroundcolor.
6+
const url = getUrl("html/pandoc-theme-print.html");
7+
8+
test("theme: pandoc — screen uses the document color variables", async ({ page }) => {
9+
await page.goto(url);
10+
await expect(page.locator("p a")).toHaveCSS("color", "rgb(255, 0, 0)");
11+
await expect(page.locator("p code")).toHaveCSS("background-color", "rgb(238, 238, 238)");
12+
});
13+
14+
test("theme: pandoc — print resets link, blockquote and code styles", async ({ page }) => {
15+
await page.emulateMedia({ media: "print" });
16+
await page.goto(url);
17+
await expect(page.locator("p a")).toHaveCSS("color", "rgb(0, 0, 0)");
18+
await expect(page.locator("blockquote")).toHaveCSS("color", "rgb(0, 0, 0)");
19+
const code = page.locator("p code");
20+
await expect(code).toHaveCSS("background-color", "rgba(0, 0, 0, 0)");
21+
await expect(code).toHaveCSS("padding-left", "0px");
22+
});

0 commit comments

Comments
 (0)