Skip to content

Commit 307bdb5

Browse files
lua: expose quarto.brand; add has_mode() function
1 parent 36e704c commit 307bdb5

File tree

10 files changed

+103
-1
lines changed

10 files changed

+103
-1
lines changed

news/changelog-1.7.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ All changes included in 1.7:
6666
## `html`
6767

6868
- ([#1325](https://github.com/quarto-dev/quarto-cli/issues/1325)): Dark Mode pages should not flash light on reload. (Nor should Light Mode pages flash dark.)
69-
- ([#1470](https://github.com/quarto-dev/quarto-cli/issues/1470)): `respect-user-color-scheme` enables checking the media query `prefers-color-scheme` for user dark mode preference. This is only on page load, not dynamic. Author preference still influences stylesheet order and NoJS experience. Defaults to `false`, leaving to author preference.
69+
- ([#1470](https://github.com/quarto-dev/quarto-cli/issues/1470)): `respect-user-color-scheme` enables checking the media query `prefers-color-scheme` for user dark mode preference. Author preference still influences stylesheet order and NoJS experience. Defaults to `false`, leaving to author preference.
7070
- ([#10780])(https://github.com/quarto-dev/quarto-cli/issues/10780)): improve `link-external-filter` documentation.
7171
- ([#11860](https://github.com/quarto-dev/quarto-cli/issues/11860)): ES6 modules that import other local JS modules in documents with `embed-resources: true` are now correctly embedded.
7272
- ([#12277](https://github.com/quarto-dev/quarto-cli/pull/12277)): Provide light and dark plot and table renderings with `renderings: [light,dark]`
@@ -144,6 +144,7 @@ All changes included in 1.7:
144144
- ([#11896](https://github.com/quarto-dev/quarto-cli/pull/11896)): fix `\f` (`{{< pagebreak >}}`) form feed character not valid in PowerPoint (`pptx`).
145145
- ([#12326](https://github.com/quarto-dev/quarto-cli/issues/12326)): Add `quarto.shortcode.*` API entry points for shortcode developers.
146146
- ([#12365](https://github.com/quarto-dev/quarto-cli/pull/12365)): `brand color` shortcode takes an optional `brandMode` second parameter, default `light`.
147+
- ([#12453](https://github.com/quarto-dev/quarto-cli/issues/12453)): Expose `_quarto.modules.brand` as `quarto.brand` and add `has_mode()` function.
147148

148149
## Lua API
149150

src/resources/filters/modules/brand/brand.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
-- brand.lua
22
-- Copyright (C) 2020-2024 Posit Software, PBC
33

4+
local function has_mode(brandMode)
5+
assert(brandMode == 'light' or brandMode == 'dark')
6+
local brand = param("brand")
7+
return (brand and brand[brandMode]) ~= nil
8+
end
9+
410
local function get_color_css(brandMode, name)
511
assert(brandMode == 'light' or brandMode == 'dark')
612
local brand = param("brand")
@@ -57,6 +63,7 @@ local function get_logo(brandMode, name)
5763
end
5864

5965
return {
66+
has_mode = has_mode,
6067
get_color_css = get_color_css,
6168
get_color = get_color,
6269
get_typography = get_typography,

src/resources/filters/modules/import_all.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ _quarto.modules = {
2222
tablecolwidths = require("modules/tablecolwidths"),
2323
typst = require("modules/typst")
2424
}
25+
26+
quarto.brand = _quarto.modules.brand
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
format: html
3+
brand:
4+
light: united-brand.yml
5+
dark: slate-brand.yml
6+
filters:
7+
- print-available-brands.lua
8+
_quarto:
9+
tests:
10+
html:
11+
ensureFileRegexMatches:
12+
-
13+
- this document has a light brand
14+
- this document has a dark brand
15+
- []
16+
---
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
format: html
3+
brand:
4+
dark: slate-brand.yml
5+
filters:
6+
- print-available-brands.lua
7+
_quarto:
8+
tests:
9+
html:
10+
ensureFileRegexMatches:
11+
-
12+
- this document has a dark brand
13+
-
14+
- this document has a light brand
15+
---
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
format: html
3+
brand:
4+
light: united-brand.yml
5+
filters:
6+
- print-available-brands.lua
7+
_quarto:
8+
tests:
9+
html:
10+
ensureFileRegexMatches:
11+
-
12+
- this document has a light brand
13+
-
14+
- this document has a dark brand
15+
---
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
format: html
3+
filters:
4+
- print-available-brands.lua
5+
_quarto:
6+
tests:
7+
html:
8+
ensureFileRegexMatches:
9+
- []
10+
-
11+
- this document has a light brand
12+
- this document has a dark brand
13+
---
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function Pandoc(doc)
2+
if not quarto.brand then return nil end
3+
if quarto.brand.has_mode('light') then
4+
doc.blocks:insert(1, pandoc.Div(quarto.utils.as_blocks("this document has a light brand")))
5+
end
6+
if quarto.brand.has_mode('dark') then
7+
quarto.log.output('has dark')
8+
doc.blocks:insert(1, pandoc.Div(quarto.utils.as_blocks("this document has a dark brand")))
9+
end
10+
return doc
11+
end
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
color:
2+
background: "#282B30"
3+
foreground: "#aaaaaa"
4+
primary: white
5+
typography:
6+
fonts:
7+
- family: "Montserrat"
8+
source: google
9+
base:
10+
family: "Montserrat"
11+
monospace-block:
12+
background-color: "#435"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
color:
2+
background: "#ffffff"
3+
foreground: "#333333"
4+
primary: red
5+
typography:
6+
fonts:
7+
- family: "Montserrat"
8+
source: google
9+
base:
10+
family: "Montserrat"

0 commit comments

Comments
 (0)