Skip to content

Commit 6676124

Browse files
authored
Merge pull request #11376 from quarto-dev/revealjs/inline-code-style
revealjs - set code-font-size as em value for variable default
2 parents 8032ec0 + b6584f6 commit 6676124

File tree

4 files changed

+38
-118
lines changed

4 files changed

+38
-118
lines changed

src/resources/formats/revealjs/quarto.scss

Lines changed: 8 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ $presentation-line-height: 1.3 !default;
1616
// and are here to simplify the implementation of _brand.yml and
1717
// user theming customization in general
1818
$font-weight-base: 400 !default;
19-
$code-font-size: $presentation-font-size-root !default;
19+
$code-font-size: 1em !default;
2020
$font-family-monospace-block: $font-family-monospace !default;
2121
$font-family-monospace-inline: $font-family-monospace !default;
2222
$link-weight: $font-weight-base !default;
@@ -25,7 +25,6 @@ $link-decoration: inherit !default;
2525
$font-weight-monospace: $font-weight-base !default;
2626
$font-weight-monospace-block: $font-weight-monospace !default;
2727
$font-weight-monospace-inline: $font-weight-monospace !default;
28-
$code-inline-font-size: $code-font-size !default;
2928

3029
// main colors
3130
$body-bg: #fff !default;
@@ -80,13 +79,14 @@ $presentation-list-bullet-color: $body-color !default;
8079
// code blocks
8180
$code-block-bg: $body-bg !default;
8281
$code-block-border-color: lighten($body-color, 60%) !default;
83-
$code-block-font-size: ($code-font-size * 0.55) !default;
82+
$code-block-font-size: $code-font-size * 0.55 !default;
8483
$code-block-height: 500px !default;
8584
$code-block-theme-dark-threshhold: 40% !default;
8685
$code-block-line-height: $presentation-line-height !default;
8786
$code-block-color: $body-color !default;
8887

8988
// inline code
89+
$code-inline-font-size: $code-font-size * 0.875 !default;
9090
$code-color: var(--quarto-hl-fu-color) !default;
9191
$code-bg: transparent !default;
9292

@@ -234,12 +234,17 @@ $overlayElementFgColor: 0, 0, 0 !default;
234234
}
235235
}
236236

237+
// Make the font size smaller by a factor of $times
238+
// Useful for font-size defined in px inside smaller font size controled by em
239+
// as they would not be impacted by the smaller font size
237240
@mixin make-smaller-font-size($element, $times: 1) {
238241
font-size: calc(
239242
#{$element} * #{quarto-math.pow($presentation-font-smaller, $times)}
240243
);
241244
}
242245

246+
// Undo the smaller font size
247+
// Useful for font-size in em already that should not be impacted by smaller font size controled by em
243248
@mixin undo-smaller-font-size($element) {
244249
font-size: calc(#{$element} / #{$presentation-font-smaller});
245250
}
@@ -505,17 +510,6 @@ $panel-sidebar-padding: 0.5em;
505510
h3 {
506511
@include undo-smaller-font-size($revealjs-h3-font-size);
507512
}
508-
// Though we want pre and code to be smaller and they are in px
509-
pre {
510-
@include make-smaller-font-size($revealjs-code-block-font-size);
511-
// Make sure code inside pre use code block font size
512-
code {
513-
font-size: inherit;
514-
}
515-
}
516-
code {
517-
@include make-smaller-font-size($revealjs-code-inline-font-size);
518-
}
519513
}
520514
}
521515

@@ -534,17 +528,6 @@ $panel-sidebar-padding: 0.5em;
534528
h3 {
535529
@include undo-smaller-font-size($revealjs-h3-font-size);
536530
}
537-
// Though we want pre and code to be smaller and they are in px
538-
pre {
539-
@include make-smaller-font-size($revealjs-code-block-font-size);
540-
// Make sure code inside pre use code block font size
541-
code {
542-
font-size: inherit;
543-
}
544-
}
545-
code {
546-
@include make-smaller-font-size($revealjs-code-inline-font-size);
547-
}
548531
}
549532

550533
// On callout we want to make the font-size smaller too
@@ -561,32 +544,6 @@ $panel-sidebar-padding: 0.5em;
561544
h3 {
562545
@include undo-smaller-font-size($revealjs-h3-font-size);
563546
}
564-
// Though we want pre and code to be smaller and they are in px
565-
pre {
566-
@include make-smaller-font-size($revealjs-code-block-font-size);
567-
// Make sure code inside pre use code block font size
568-
code {
569-
font-size: inherit;
570-
}
571-
}
572-
code {
573-
@include make-smaller-font-size($revealjs-code-inline-font-size);
574-
}
575-
}
576-
// twice for code / pre inside callout if inside a smaller slide
577-
// this is because they are passed in pixels
578-
&.smaller div.callout {
579-
// Though we want pre and code to be smaller and they are in px
580-
pre {
581-
@include make-smaller-font-size($revealjs-code-block-font-size, 2);
582-
// Make sure code inside pre use code block font size
583-
code {
584-
font-size: inherit;
585-
}
586-
}
587-
code {
588-
@include make-smaller-font-size($revealjs-code-inline-font-size, 2);
589-
}
590547
}
591548
}
592549
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Every test is a call to `testthat::test_that()` function.
2323

2424
- And inside a list : `1+1`
2525

26-
## Highlited Cell
26+
## Highlighted Cell
2727

2828
````{.python}
2929
1 + 1

tests/integration/playwright/src/utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,10 @@ export async function getCSSProperty(loc: Locator, variable: string, asNumber =
151151
export async function checkFontSizeIdentical(loc1: Locator, loc2: Locator) {
152152
const loc1FontSize = await getCSSProperty(loc1, 'font-size', false) as string;
153153
await expect(loc2).toHaveCSS('font-size', loc1FontSize);
154+
}
155+
156+
export async function checkFontSizeSimilar(loc1: Locator, loc2: Locator, factor: number = 1) {
157+
const loc1FontSize = await getCSSProperty(loc1, 'font-size', true) as number;
158+
const loc2FontSize = await getCSSProperty(loc2, 'font-size', true) as number;
159+
await expect(loc1FontSize).toBeCloseTo(loc2FontSize * factor);
154160
}

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

Lines changed: 23 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { test, expect, Locator } from '@playwright/test';
2-
import { asRGB, checkColor, checkFontSizeIdentical, getCSSProperty, RGBColor } from '../src/utils';
2+
import { asRGB, checkColor, checkFontSizeIdentical, checkFontSizeSimilar, getCSSProperty, RGBColor } from '../src/utils';
33

44
async function getRevealMainFontSize(page: any): Promise<number> {
55
return await getCSSProperty(page.locator('body'), "--r-main-font-size", true) as number;
@@ -16,25 +16,25 @@ async function getRevealCodeInlineFontSize(page: any): Promise<number> {
1616

1717
test('Code font size in callouts and smaller slide is scaled down', async ({ page }) => {
1818
await page.goto('./revealjs/code-font-size.html');
19-
await page.locator('body').press('ArrowRight');
2019
// Get smaller slide scale factor
2120
const calloutsFontSize = await getCSSProperty(page.locator('#callouts div.callout'), "font-size", true) as number;
2221
const mainFontSize = await getRevealMainFontSize(page);
2322
const scaleFactor = calloutsFontSize / mainFontSize;
2423
expect(scaleFactor).toBeLessThan(1);
24+
// Get non smaller size
25+
const codeBlockFontSizeDefault = await getCSSProperty(page.locator('#highlighted-cell pre'), "font-size", true) as number;
26+
const codeInlineFontSizeDefault = await getCSSProperty(page.locator('#no-callout-inline').getByText('testthat::test_that()'), "font-size", true) as number;
2527
// Font size in callout for inline code should be scaled smaller than default inline code
28+
expect(await getCSSProperty(page.locator('#callouts').getByText('testthat::test_that()'), "font-size", true)).toBeCloseTo(codeInlineFontSizeDefault * scaleFactor);
29+
// Font size for code block in callout should be scaled smaller that default code block
30+
expect(await getCSSProperty(page.locator('#callouts .callout pre code'), 'font-size', true)).toBeCloseTo(codeBlockFontSizeDefault * scaleFactor);
31+
// Font size in callout for inline code should be samely size as text than by default
2632
const codeInlineFontSize = await getRevealCodeInlineFontSize(page);
27-
const computedInlineFontSize = scaleFactor * codeInlineFontSize;
28-
expect(await getCSSProperty(page.locator('#callouts').getByText('testthat::test_that()'), 'font-size', true)).toBeCloseTo(computedInlineFontSize);
29-
// Font size in callout for inline code should be same size as text by default
30-
await checkFontSizeIdentical(
31-
page.locator('#callouts').getByText('Every test is a call to'),
32-
page.locator('#callouts').getByText('testthat::test_that()')
33+
await checkFontSizeSimilar(
34+
page.locator('#callouts').getByText('testthat::test_that()'),
35+
page.locator('#callouts').getByText('Every test is a call to'),
36+
codeInlineFontSize
3337
);
34-
// Font size for code block in callout should be scaled smaller that default code block
35-
const codeBlockFontSize = await getRevealCodeBlockFontSize(page)
36-
const computedBlockFontSize = scaleFactor * codeBlockFontSize;
37-
expect(await getCSSProperty(page.locator('#callouts .callout pre code'), 'font-size', true)).toBeCloseTo(computedBlockFontSize);
3838
});
3939

4040
test('Code font size in smaller slide is scaled down', async ({ page }) => {
@@ -44,63 +44,20 @@ test('Code font size in smaller slide is scaled down', async ({ page }) => {
4444
const mainFontSize = await getRevealMainFontSize(page);
4545
const scaleFactor = smallerFontSize / mainFontSize;
4646
expect(scaleFactor).toBeLessThan(1);
47-
// Code Font size in smaller slide for inline code should be scaled smaller than default inline code
48-
const codeInlineFontSize = await getRevealCodeInlineFontSize(page);
49-
const computedInlineFontSize = scaleFactor * codeInlineFontSize;
50-
expect(
51-
await getCSSProperty(
52-
page.locator('#smaller-slide p').filter({ hasText: 'Some inline code' }).getByRole('code'),
53-
'font-size', true
54-
)
55-
).toBeCloseTo(computedInlineFontSize);
56-
// Font size for code block in callout should be scaled smaller that default code block
57-
const codeBlockFontSize = await getRevealCodeBlockFontSize(page)
58-
const computedBlockFontSize = scaleFactor * codeBlockFontSize;
59-
expect(await getCSSProperty(page.locator('#smaller-slide pre').getByRole('code'), 'font-size', true)).toBeCloseTo(computedBlockFontSize);
60-
});
61-
62-
test('Code font size in callouts in smaller slide is scaled down twice', async ({ page }) => {
63-
await page.goto('./revealjs/code-font-size.html#/smaller-slide2');
64-
// Get smaller slide scale factor
65-
const smallerFontSize = await getCSSProperty(page.locator('#smaller-slide2').getByText('And block code:', { exact: true }), "font-size", true) as number;
66-
const mainFontSize = await getRevealMainFontSize(page);
67-
const scaleFactor = smallerFontSize / mainFontSize;
68-
expect(scaleFactor).toBeLessThan(1);
47+
// Get non smaller size
48+
const codeBlockFontSizeDefault = await getCSSProperty(page.locator('#highlighted-cell pre'), "font-size", true) as number;
49+
const codeInlineFontSizeDefault = await getCSSProperty(page.locator('#no-callout-inline').getByText('testthat::test_that()'), "font-size", true) as number;
6950
// Font size in callout for inline code should be scaled smaller than default inline code
70-
const codeInlineFontSize = await getRevealCodeInlineFontSize(page);
71-
const computedInlineFontSize = scaleFactor * codeInlineFontSize;
72-
expect(await getCSSProperty(page.locator('#smaller-slide2').getByText('1 + 1'), 'font-size', true)).toBeCloseTo(computedInlineFontSize);
73-
// Font size in callout for inline code should be same size as text by default
74-
await checkFontSizeIdentical(
75-
page.locator('#smaller-slide2').getByText('Some inline code'),
76-
page.locator('#smaller-slide2').getByText('1 + 1')
77-
);
51+
expect(await getCSSProperty(page.locator('#smaller-slide p').filter({ hasText: 'Some inline code' }).getByRole('code'), "font-size", true)).toBeCloseTo(codeInlineFontSizeDefault * scaleFactor);
7852
// Font size for code block in callout should be scaled smaller that default code block
79-
const codeBlockFontSize = await getRevealCodeBlockFontSize(page)
80-
const computedBlockFontSize = scaleFactor * codeBlockFontSize;
81-
expect(await getCSSProperty(page.locator('#smaller-slide2 .callout pre code'), 'font-size', true)).toBeCloseTo(computedBlockFontSize);
82-
});
83-
84-
test('Code font size is correctly set', async ({ page }) => {
85-
await page.goto('./revealjs/code-font-size.html');
86-
await page.locator('body').press('ArrowRight');
87-
await page.locator('body').press('ArrowRight');
53+
expect(await getCSSProperty(page.locator('#smaller-slide pre').getByRole('code'), 'font-size', true)).toBeCloseTo(codeBlockFontSizeDefault * scaleFactor);
54+
// Font size in callout for inline code should be samely size as text than by default
8855
const codeInlineFontSize = await getRevealCodeInlineFontSize(page);
89-
expect(
90-
await getCSSProperty(page.locator('#no-callout-inline').getByText('testthat::test_that()'), 'font-size', true)
91-
).toBeCloseTo(codeInlineFontSize);
92-
expect(
93-
await getCSSProperty(page.getByText('1+1', { exact: true }), 'font-size', true)
94-
).toBeCloseTo(codeInlineFontSize);
95-
await page.locator('body').press('ArrowRight');
96-
const codeBlockFontSize = await getRevealCodeBlockFontSize(page);
97-
expect(
98-
await getCSSProperty(page.locator("#highlited-cell div.sourceCode pre code"), 'font-size', true)
99-
).toBeCloseTo(codeBlockFontSize);
100-
await page.locator('body').press('ArrowRight');
101-
expect(
102-
await getCSSProperty(page.locator("#non-highligted pre code"), 'font-size', true)
103-
).toBeCloseTo(codeBlockFontSize);
56+
await checkFontSizeSimilar(
57+
page.locator('#smaller-slide2').getByText('+ 1'),
58+
page.locator('#smaller-slide2').getByText('Some inline code'),
59+
codeInlineFontSize
60+
);
10461
});
10562

10663
test('Callouts can be customized using SCSS variables', async ({ page }) => {

0 commit comments

Comments
 (0)