Skip to content

Commit 78877e0

Browse files
authored
Quote brand font family names in the generated CSS (#15103)
Brand font families were written into the generated CSS unquoted. A family with a part starting with a digit, such as "Source Sans 3", then became an invalid font-family declaration that browsers drop. Family values now go through asCssFont, the helper mainfont and monofont already use. revealjs needed the same fix because reveal.js builds its font custom properties by interpolation, which also drops the quotes. - Quote brand typography families with asCssFont. - In revealjs, re-declare --r-main-font, --r-heading-font and --r-code-font with inspect() in quarto.scss. This also fixes mainfont in revealjs without a brand. - Use inspect() for --mermaid-font-family. Fixes #14882
1 parent 6872bdc commit 78877e0

7 files changed

Lines changed: 74 additions & 3 deletions

File tree

‎news/changelog-1.11.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ All changes included in 1.11:
4242
### All Formats
4343

4444
- ([#14772](https://github.com/quarto-dev/quarto-cli/issues/14772)): Custom `language` keys now reach templates through `$quarto.language.<key>$`. A key that Quarto does not ship passed schema validation and was merged over the defaults, then discarded before templates saw it, so it expanded to an empty string with no warning. (author: @mcanouil)
45+
- ([#14882](https://github.com/quarto-dev/quarto-cli/issues/14882)): Fix brand font families with a word starting with a digit, such as `Source Sans 3`, not applying in `html` and `revealjs` output. The same names in `mainfont` now also apply in `revealjs`. (author: @Masad791)
4546

4647
### `dashboard`
4748

‎src/core/sass/brand.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { darkModeDefault } from "../../format/html/format-html-info.ts";
2727
import { kBrandMode } from "../../config/constants.ts";
2828
import { join, relative } from "../../deno_ral/path.ts";
2929
import { isExternalPath } from "../url.ts";
30+
import { asCssFont } from "../css.ts";
3031

3132
const defaultColorNameMap: Record<string, string> = {
3233
"link-color": "link",
@@ -543,6 +544,11 @@ const brandTypographyLayer = (
543544
let value = fontInformation[source];
544545
if (["color", "background-color"].includes(source)) {
545546
value = brand.getColor(value as string);
547+
} else if (source === "family") {
548+
// quote names with spaces, as the mainfont/monofont path does: an
549+
// unquoted name with a part starting with a digit ("Source Sans 3")
550+
// is invalid CSS and the browser drops the declaration
551+
value = asCssFont(value) ?? value;
546552
}
547553
typographyVariables.push(
548554
`$${target}: ${value} !default;`,

‎src/resources/formats/html/_quarto-rules.scss‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ $mermaid-node-fg-color: $primary !default;
734734
--mermaid-fg-color: #{$mermaid-fg-color};
735735
--mermaid-fg-color--lighter: #{$mermaid-fg-color--lighter};
736736
--mermaid-fg-color--lightest: #{$mermaid-fg-color--lightest};
737-
--mermaid-font-family: #{$mermaid-font-family};
737+
--mermaid-font-family: #{inspect($mermaid-font-family)};
738738
--mermaid-label-bg-color: #{$mermaid-label-bg-color};
739739
--mermaid-label-fg-color: #{$mermaid-label-fg-color};
740740
--mermaid-node-bg-color: #{$mermaid-node-bg-color};

‎src/resources/formats/revealjs/quarto.scss‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -856,8 +856,13 @@ kbd {
856856
}
857857

858858
:root {
859-
--r-inline-code-font: #{$font-family-monospace-inline};
860-
--r-block-code-font: #{$font-family-monospace-block};
859+
// inspect() keeps the quotes of a family name like "Source Sans 3", which
860+
// plain interpolation drops; reveal.js' exposer.scss writes these without them
861+
--r-main-font: #{inspect($mainFont)};
862+
--r-heading-font: #{inspect($headingFont)};
863+
--r-code-font: #{inspect($codeFont)};
864+
--r-inline-code-font: #{inspect($font-family-monospace-inline)};
865+
--r-block-code-font: #{inspect($font-family-monospace-block)};
861866
--r-inline-code-font-size: #{$revealjs-code-inline-font-size};
862867
--r-block-code-font-size: #{$revealjs-code-block-font-size};
863868
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
title: "Issue 14882 - mainfont and monofont names are quoted in revealjs CSS"
3+
format: revealjs
4+
mainfont: Source Sans 3
5+
monofont: M PLUS 1 Code
6+
_quarto:
7+
tests:
8+
revealjs:
9+
ensureCssRegexMatches:
10+
- ['--r-main-font:\s*"Source Sans 3"', '--r-heading-font:\s*"Source Sans 3"', '--r-code-font:\s*"M PLUS 1 Code"', '--r-inline-code-font:\s*"M PLUS 1 Code"', '--r-block-code-font:\s*"M PLUS 1 Code"']
11+
# reveal.js' exposer.scss still writes the values unquoted first; an unquoted one after Quarto's quoted one would win
12+
- ['--r-main-font:\s*"Source Sans 3"[\s\S]*--r-main-font:\s*Source Sans 3', '--r-heading-font:\s*"Source Sans 3"[\s\S]*--r-heading-font:\s*Source Sans 3', '--r-code-font:\s*"M PLUS 1 Code"[\s\S]*--r-code-font:\s*M PLUS 1 Code']
13+
---
14+
15+
## A slide
16+
17+
Without a brand, `mainfont` and `monofont` names with a word starting with a digit must keep their quotes in the reveal.js font variables. Body text and `inline code`.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
title: "Issue 14882 - brand font family names are quoted in revealjs CSS"
3+
format: revealjs
4+
brand:
5+
typography:
6+
base: Source Sans 3
7+
headings: Bricolage Grotesque 96pt
8+
monospace: M PLUS 1 Code
9+
_quarto:
10+
tests:
11+
revealjs:
12+
ensureCssRegexMatches:
13+
- ['--r-main-font:\s*"Source Sans 3"', '--r-heading-font:\s*"Bricolage Grotesque 96pt"', '--r-code-font:\s*"M PLUS 1 Code"', '--mermaid-font-family:\s*"Source Sans 3"']
14+
# reveal.js' exposer.scss still writes the values unquoted first; an unquoted one after Quarto's quoted one would win
15+
- ['--r-main-font:\s*"Source Sans 3"[\s\S]*--r-main-font:\s*Source Sans 3', '--r-heading-font:\s*"Bricolage Grotesque 96pt"[\s\S]*--r-heading-font:\s*Bricolage Grotesque 96pt', '--r-code-font:\s*"M PLUS 1 Code"[\s\S]*--r-code-font:\s*M PLUS 1 Code']
16+
---
17+
18+
## A slide
19+
20+
Body text and `inline code`.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
title: "Issue 14882 - brand font family names are quoted in CSS"
3+
format: html
4+
brand:
5+
typography:
6+
fonts:
7+
- family: Source Sans 3
8+
source: google
9+
base: Source Sans 3
10+
headings: Bricolage Grotesque 96pt
11+
monospace: M PLUS 1 Code
12+
_quarto:
13+
tests:
14+
html:
15+
ensureCssRegexMatches:
16+
- ['--bs-body-font-family:\s*"Source Sans 3"', 'font-family:\s*"Bricolage Grotesque 96pt"', '--bs-font-monospace:\s*"M PLUS 1 Code"', '--mermaid-font-family:\s*"Source Sans 3"']
17+
- ['font-family:\s*Source Sans 3', 'font-family:\s*Bricolage Grotesque 96pt', 'monospace:\s*M PLUS 1 Code']
18+
---
19+
20+
## A heading
21+
22+
Body text and `inline code`.

0 commit comments

Comments
 (0)