Skip to content

Commit bcd87c9

Browse files
implement brand-mode for revealjs
fixes #12550
1 parent a7c7778 commit bcd87c9

File tree

9 files changed

+124
-9
lines changed

9 files changed

+124
-9
lines changed

news/changelog-1.8.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ All changes included in 1.8:
3333

3434
### `revealjs`
3535

36+
- ([#12550](https://github.com/quarto-dev/quarto-cli/issues/12550)): Revealjs supports `brand-mode`, allowing to select either the light or the dark brand.
3637
- ([#12598](https://github.com/quarto-dev/quarto-cli/pull/12598)): Ensure `.fragment` on an image with caption applies to whole figure.
3738
- ([#12716](https://github.com/quarto-dev/quarto-cli/issues/12716)): Correctly resolve `"brand"` set in `theme` configuration for document in subdirectory from project root.
3839
- Use `cdn.jsdelivr.net` for mathjax dependencies to ensure consistent CDN usage across formats. Previously, `cdnjs.cloudflare.com` was used for `revealjs` mathjax dependencies, while `cdn.jsdelivr.net` was used for html format.
@@ -43,7 +44,7 @@ All changes included in 1.8:
4344

4445
### `typst`
4546

46-
- ([#12180](https://github.com/quarto-dev/quarto-cli/issues/12180): Typst schema / autocomplete for `logo` option has `path` and `alt`.
47+
- ([#12180](https://github.com/quarto-dev/quarto-cli/issues/12180)): Typst schema / autocomplete for `logo` option has `path` and `alt`.
4748
- ([#12554](https://github.com/quarto-dev/quarto-cli/pull/12554)): CSS properties `font-weight` and `font-style` are translated to Typst `text` properties.
4849
- ([#12695](https://github.com/quarto-dev/quarto-cli/issues/12695)): Resolve Typst `font-paths` that start with `/` relative to project root.
4950
- ([#12739](https://github.com/quarto-dev/quarto-cli/pull/12739)): Remove unused variable `heading-background-color` and `heading-decoration` from Typst's templates. They are leftover from previous change, and not part of Brand.yml schema for typography of headings.

src/core/sass/brand.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
} from "../../resources/types/zod/schema-types.ts";
2525
import { Brand } from "../brand/brand.ts";
2626
import { darkModeDefault } from "../../format/html/format-html-info.ts";
27+
import { kBrandMode } from "../../config/constants.ts";
2728

2829
const defaultColorNameMap: Record<string, string> = {
2930
"link-color": "link",
@@ -634,14 +635,18 @@ export async function brandBootstrapSassLayers(
634635

635636
export async function brandRevealSassLayers(
636637
input: string | undefined,
637-
_format: Format,
638+
format: Format,
638639
project: ProjectContext,
639640
): Promise<SassLayer[]> {
641+
let brandMode: "light" | "dark" = "light";
642+
if (format.metadata[kBrandMode] === "dark") {
643+
brandMode = "dark";
644+
}
640645
return (await brandSassLayers(
641646
input,
642647
project,
643648
defaultColorNameMap,
644-
)).light;
649+
))[brandMode];
645650
}
646651

647652
export async function brandSassFormatExtras(

src/format/reveal/format-reveal.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { join } from "../../deno_ral/path.ts";
77

88
import { Document, Element, NodeType } from "../../core/deno-dom.ts";
99
import {
10+
kBrandMode,
1011
kCodeLineNumbers,
1112
kFrom,
1213
kHtmlMathMethod,
@@ -376,8 +377,11 @@ export function revealjsFormat() {
376377
);
377378
}
378379

379-
const determineRevealLogo = (format: Format): string | undefined => {
380-
const brandData = format.render.brand?.light?.processedData;
380+
const determineRevealLogo = (
381+
brandMode: "light" | "dark",
382+
format: Format,
383+
): string | undefined => {
384+
const brandData = format.render.brand?.[brandMode]?.processedData;
381385
if (brandData?.logo) {
382386
// add slide logo if we have one
383387
for (const size of Zod.BrandNamedLogo.options) {
@@ -393,6 +397,10 @@ const determineRevealLogo = (format: Format): string | undefined => {
393397
};
394398

395399
function revealMarkdownAfterBody(format: Format) {
400+
let brandMode: "light" | "dark" = "light";
401+
if (format.metadata[kBrandMode] === "dark") {
402+
brandMode = "dark";
403+
}
396404
const lines: string[] = [];
397405
lines.push("::: {.quarto-auto-generated-content style='display: none;'}\n");
398406
let revealLogo = format
@@ -402,15 +410,15 @@ function revealMarkdownAfterBody(format: Format) {
402410
revealLogo = revealLogo.path;
403411
}
404412
if (Zod.BrandNamedLogo.options.includes(revealLogo as BrandNamedLogo)) {
405-
const brandData = format.render.brand?.light?.processedData;
413+
const brandData = format.render.brand?.[brandMode]?.processedData;
406414
const logoInfo = brandData?.logo
407415
?.[revealLogo as BrandNamedLogo];
408416
if (logoInfo) {
409417
revealLogo = logoInfo.path;
410418
}
411419
}
412420
} else {
413-
revealLogo = determineRevealLogo(format);
421+
revealLogo = determineRevealLogo(brandMode, format);
414422
}
415423
if (revealLogo) {
416424
lines.push(

src/resources/schema/document-layout.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@
5353
enum: [light, dark]
5454
default: light
5555
tags:
56-
formats: [typst]
56+
formats: [typst, revealjs]
5757
description: |
58-
The brand mode to use for rendering the Typst document, `light` or `dark`.
58+
The brand mode to use for rendering the document, `light` or `dark`.
5959
6060
- name: layout
6161
schema:
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: brand-mode and revealjs
3+
format: revealjs
4+
brand:
5+
logo:
6+
medium:
7+
light: sun-face.png
8+
dark: moon-face.png
9+
color:
10+
foreground:
11+
light: '#222'
12+
dark: '#eee'
13+
background:
14+
light: '#eee'
15+
dark: '#222'
16+
typography:
17+
headings:
18+
color:
19+
light: '#429'
20+
dark: '#54e'
21+
brand-mode: dark
22+
_quarto:
23+
tests:
24+
revealjs:
25+
ensureHtmlElements:
26+
-
27+
- 'img[src="moon-face.png"]'
28+
-
29+
- 'img[src="sun-face.png"]'
30+
---
31+
32+
## Here's a slide
33+
34+
- in {{< meta brand-mode >}} mode!
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
title: brand-mode and revealjs
3+
format: revealjs
4+
brand:
5+
logo:
6+
medium:
7+
light: sun-face.png
8+
dark: moon-face.png
9+
color:
10+
foreground:
11+
light: '#222'
12+
dark: '#eee'
13+
background:
14+
light: '#eee'
15+
dark: '#222'
16+
typography:
17+
headings:
18+
color:
19+
light: '#429'
20+
dark: '#54e'
21+
_quarto:
22+
tests:
23+
revealjs:
24+
ensureHtmlElements:
25+
-
26+
- 'img[src="sun-face.png"]'
27+
-
28+
- 'img[src="moon-face.png"]'
29+
---
30+
31+
## Here's a slide
32+
33+
- in {{< meta brand-mode >}} mode!
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: brand-mode and revealjs
3+
format: revealjs
4+
brand:
5+
logo:
6+
medium:
7+
light: sun-face.png
8+
dark: moon-face.png
9+
color:
10+
foreground:
11+
light: '#222'
12+
dark: '#eee'
13+
background:
14+
light: '#eee'
15+
dark: '#222'
16+
typography:
17+
headings:
18+
color:
19+
light: '#429'
20+
dark: '#54e'
21+
brand-mode: light
22+
_quarto:
23+
tests:
24+
revealjs:
25+
ensureHtmlElements:
26+
-
27+
- 'img[src="sun-face.png"]'
28+
-
29+
- 'img[src="moon-face.png"]'
30+
---
31+
32+
## Here's a slide
33+
34+
- in {{< meta brand-mode >}} mode!
67.8 KB
Loading
80.7 KB
Loading

0 commit comments

Comments
 (0)