Skip to content

Commit ccd8095

Browse files
committed
Code in callouts in smaller slides needs to be scaled down twice
This is because code-.*-font-size variables are set in px and not em, and we need to scaled down using `calc()` twice so that correct font is used.
1 parent a0c23f6 commit ccd8095

File tree

3 files changed

+54
-4
lines changed

3 files changed

+54
-4
lines changed

src/resources/formats/revealjs/quarto.scss

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,10 @@ $overlayElementFgColor: 0, 0, 0 !default;
224224
}
225225
}
226226

227-
@mixin make-smaller-font-size($element) {
228-
font-size: calc(#{$element} * #{$presentation-font-smaller});
227+
@mixin make-smaller-font-size($element, $times: 1) {
228+
font-size: calc(
229+
#{$element} * #{quarto-math.pow($presentation-font-smaller, $times)}
230+
);
229231
}
230232

231233
@mixin undo-smaller-font-size($element) {
@@ -561,6 +563,21 @@ $panel-sidebar-padding: 0.5em;
561563
@include make-smaller-font-size($revealjs-code-inline-font-size);
562564
}
563565
}
566+
// twice for code / pre inside callout if inside a smaller slide
567+
// this is because they are passed in pixels
568+
&.smaller div.callout {
569+
// Though we want pre and code to be smaller and they are in px
570+
pre {
571+
@include make-smaller-font-size($revealjs-code-block-font-size, 2);
572+
// Make sure code inside pre use code block font size
573+
code {
574+
font-size: inherit;
575+
}
576+
}
577+
code {
578+
@include make-smaller-font-size($revealjs-code-inline-font-size, 2);
579+
}
580+
}
564581
}
565582
}
566583

tests/docs/playwright/revealjs/code-font-size.qmd

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,15 @@ And block code:
4747
1 + 1
4848
```
4949

50+
## Smaller slide with callouts {#smaller-slide2 .smaller}
5051

52+
::: {.callout-note}
53+
54+
Some inline code: `1 + 1`
55+
56+
And block code:
57+
58+
```{.r}
59+
2 + 2
60+
```
61+
:::

tests/integration/playwright/tests/revealjs-themes.spec.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ test('Code font size in callouts and smaller slide is scaled down', async ({ pag
4949
// Font size for code block in callout should be scaled smaller that default code block
5050
const codeBlockFontSize = await getRevealCodeBlockFontSize(page)
5151
const computedBlockFontSize = scaleFactor * codeBlockFontSize;
52-
expect(await getCSSProperty(page.locator('.callout pre code'), 'font-size', true)).toBeCloseTo(computedBlockFontSize);
52+
expect(await getCSSProperty(page.locator('#callouts .callout pre code'), 'font-size', true)).toBeCloseTo(computedBlockFontSize);
5353
});
5454

5555
test('Code font size in smaller slide is scaled down', async ({ page }) => {
5656
await page.goto('./revealjs/code-font-size.html#/smaller-slide');
5757
// Get smaller slide scale factor
58-
const smallerFontSize = await getCSSProperty(page.getByText('And block code:', { exact: true }), "font-size", true) as number;
58+
const smallerFontSize = await getCSSProperty(page.locator("#smaller-slide").getByText('And block code:', { exact: true }), "font-size", true) as number;
5959
const mainFontSize = await getRevealMainFontSize(page);
6060
const scaleFactor = smallerFontSize / mainFontSize;
6161
expect(scaleFactor).toBeLessThan(1);
@@ -74,6 +74,28 @@ test('Code font size in smaller slide is scaled down', async ({ page }) => {
7474
expect(await getCSSProperty(page.locator('#smaller-slide pre').getByRole('code'), 'font-size', true)).toBeCloseTo(computedBlockFontSize);
7575
});
7676

77+
test('Code font size in callouts in smaller slide is scaled down twice', async ({ page }) => {
78+
await page.goto('./revealjs/code-font-size.html#/smaller-slide2');
79+
// Get smaller slide scale factor
80+
const smallerFontSize = await getCSSProperty(page.locator('#smaller-slide2').getByText('And block code:', { exact: true }), "font-size", true) as number;
81+
const mainFontSize = await getRevealMainFontSize(page);
82+
const scaleFactor = smallerFontSize / mainFontSize;
83+
expect(scaleFactor).toBeLessThan(1);
84+
// Font size in callout for inline code should be scaled smaller than default inline code
85+
const codeInlineFontSize = await getRevealCodeInlineFontSize(page);
86+
const computedInlineFontSize = scaleFactor * codeInlineFontSize;
87+
expect(await getCSSProperty(page.locator('#smaller-slide2').getByText('1 + 1'), 'font-size', true)).toBeCloseTo(computedInlineFontSize);
88+
// Font size in callout for inline code should be same size as text by default
89+
await checkFontSizeIdentical(
90+
page.locator('#smaller-slide2').getByText('Some inline code'),
91+
page.locator('#smaller-slide2').getByText('1 + 1')
92+
);
93+
// Font size for code block in callout should be scaled smaller that default code block
94+
const codeBlockFontSize = await getRevealCodeBlockFontSize(page)
95+
const computedBlockFontSize = scaleFactor * codeBlockFontSize;
96+
expect(await getCSSProperty(page.locator('#smaller-slide2 .callout pre code'), 'font-size', true)).toBeCloseTo(computedBlockFontSize);
97+
});
98+
7799
test('Code font size is correctly set', async ({ page }) => {
78100
await page.goto('./revealjs/code-font-size.html');
79101
await page.locator('body').press('ArrowRight');

0 commit comments

Comments
 (0)