Skip to content

Commit 2e0c935

Browse files
brand-mode: choose light or dark brand for Typst
1 parent 11ffb94 commit 2e0c935

File tree

10 files changed

+184
-3
lines changed

10 files changed

+184
-3
lines changed

src/command/render/filters.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { existsSync } from "../../deno_ral/fs.ts";
99
import {
1010
kBibliography,
1111
kBrand,
12+
kBrandMode,
1213
kCitationLocation,
1314
kCiteMethod,
1415
kClearCellOptions,
@@ -909,6 +910,7 @@ const extractTypstFilterParams = (format: Format) => {
909910
[kTocIndent]: format.metadata[kTocIndent],
910911
[kLogo]: format.metadata[kLogo],
911912
[kCssPropertyProcessing]: format.metadata[kCssPropertyProcessing],
913+
[kBrandMode]: format.metadata[kBrandMode],
912914
[kHtmlPreTagProcessing]: format.metadata[kHtmlPreTagProcessing],
913915
};
914916
};

src/config/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ export const kFontPaths = "font-paths";
141141
export const kHtmlTableProcessing = "html-table-processing";
142142
export const kHtmlPreTagProcessing = "html-pre-tag-processing";
143143
export const kCssPropertyProcessing = "css-property-processing";
144+
export const kBrandMode = "brand-mode";
144145
export const kUseRsvgConvert = "use-rsvg-convert";
145146
export const kValidateYaml = "validate-yaml";
146147

src/resources/filters/modules/typst_css.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ local typst_named_colors = {
176176
lime = '#01ff70',
177177
}
178178

179-
local brandMode = 'light' --- ugh
179+
local brandMode = param('brand-mode') or 'light'
180180

181181
-- css can have fraction or percent
182182
-- typst can have int or percent
@@ -748,6 +748,7 @@ local function expand_side_shorthand(items, context, warnings)
748748
end
749749

750750
return {
751+
set_brand_mode = set_brand_mode,
751752
parse_color = parse_color,
752753
parse_opacity = parse_opacity,
753754
output_color = output_color,

src/resources/filters/quarto-post/cell-renderings.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ function choose_cell_renderings()
4747
if quarto.format.isHtmlOutput() and lightDiv and darkDiv then
4848
blocks:insert(pandoc.Div(lightDiv.content, pandoc.Attr("", {'light-content'}, {})))
4949
blocks:insert(pandoc.Div(darkDiv.content, pandoc.Attr("", {'dark-content'}, {})))
50+
elseif quarto.format.isTypstOutput() and lightDiv and darkDiv then
51+
local brandMode = param('brand-mode') or 'light'
52+
if brandMode == 'light' then
53+
blocks:insert(lightDiv)
54+
elseif brandMode == 'dark' then
55+
blocks:insert(darkDiv)
56+
end
5057
else
5158
blocks:insert(lightDiv or darkDiv)
5259
end

src/resources/filters/quarto-post/typst-brand-yaml.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function render_typst_brand_yaml()
5959
return {
6060
Pandoc = function(pandoc0)
6161
local brand = param('brand')
62-
local brandMode = 'light'
62+
local brandMode = param('brand-mode') or 'light'
6363
brand = brand and brand[brandMode]
6464
if brand and brand.processedData then
6565
-- color
@@ -300,7 +300,7 @@ function render_typst_brand_yaml()
300300
end
301301
end,
302302
Meta = function(meta)
303-
local brandMode = 'light'
303+
local brandMode = param('brand-mode') or 'light'
304304
-- it can contain the path but we want to store an object here
305305
if not meta.brand or pandoc.utils.type(meta.brand) == 'Inlines' then
306306
meta.brand = {}

src/resources/schema/document-layout.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@
4848
description: |
4949
The paper size for the document.
5050
51+
- name: brand-mode
52+
schema:
53+
enum: [light, dark]
54+
default: light
55+
tags:
56+
formats: [typst]
57+
description: |
58+
The brand mode to use for rendering the Typst document, `light` or `dark`.
59+
5160
- name: layout
5261
schema:
5362
maybeArrayOf: string
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
title: Translate brand named color references from CSS to Typst
3+
format:
4+
typst:
5+
keep-typ: true
6+
brand-mode: dark
7+
brand:
8+
light:
9+
color:
10+
palette:
11+
dark-grey: "#444"
12+
blue: "#82aeef"
13+
dark:
14+
color:
15+
palette:
16+
dark-grey: "#222"
17+
blue: "#415777"
18+
_quarto:
19+
tests:
20+
typst:
21+
ensureTypstFileRegexMatches:
22+
-
23+
- '#block\(fill: brand-color\.dark-grey\)\[\s*#set text\(fill: brand-color\.blue\);'
24+
- 'blue: rgb\("#415777"\)'
25+
- 'dark-grey: rgb\("#222"\)'
26+
- []
27+
---
28+
29+
30+
```{=typst}
31+
// stopgap to make this look ok
32+
#set block(inset: 6pt)
33+
```
34+
35+
:::{style="background-color: var(--brand-dark-grey); color: var(--brand-blue)"}
36+
This div is blue on dark grey.
37+
:::
38+
39+
{{< lipsum 2 >}}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
title: Translate brand named color references from CSS to Typst
3+
format:
4+
typst:
5+
keep-typ: true
6+
brand:
7+
light:
8+
color:
9+
palette:
10+
dark-grey: "#444"
11+
blue: "#82aeef"
12+
dark:
13+
color:
14+
palette:
15+
dark-grey: "#222"
16+
blue: "#415777"
17+
_quarto:
18+
tests:
19+
typst:
20+
ensureTypstFileRegexMatches:
21+
-
22+
- '#block\(fill: brand-color\.dark-grey\)\[\s*#set text\(fill: brand-color\.blue\);'
23+
- 'blue: rgb\("#82aeef"\)'
24+
- 'dark-grey: rgb\("#444"\)'
25+
- []
26+
---
27+
28+
29+
```{=typst}
30+
// stopgap to make this look ok
31+
#set block(inset: 6pt)
32+
```
33+
34+
:::{style="background-color: var(--brand-dark-grey); color: var(--brand-blue)"}
35+
This div is blue on dark grey.
36+
:::
37+
38+
{{< lipsum 2 >}}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
title: Translate brand named color references from CSS to Typst
3+
format:
4+
typst:
5+
keep-typ: true
6+
brand-mode: dark
7+
brand:
8+
light:
9+
color:
10+
palette:
11+
light-grey: "#444"
12+
blue: "#82aeef"
13+
dark:
14+
color:
15+
palette:
16+
dark-grey: "#222"
17+
blue: "#415777"
18+
_quarto:
19+
tests:
20+
typst:
21+
ensureTypstFileRegexMatches:
22+
-
23+
- 'blue: rgb\("#415777"\)'
24+
- 'dark-grey: rgb\("#222"\)'
25+
- '#set text\(fill: brand-color\.blue\);'
26+
-
27+
printsMessage:
28+
level: INFO
29+
regex: 'unknown brand color light-grey'
30+
---
31+
32+
33+
```{=typst}
34+
// stopgap to make this look ok
35+
#set block(inset: 6pt)
36+
```
37+
38+
:::{style="background-color: var(--brand-light-grey); color: var(--brand-blue)"}
39+
This div is blue on dark grey.
40+
:::
41+
42+
{{< lipsum 2 >}}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
title: Translate brand named color references from CSS to Typst
3+
format:
4+
typst:
5+
keep-typ: true
6+
brand-mode: light
7+
brand:
8+
light:
9+
color:
10+
palette:
11+
light-grey: "#444"
12+
blue: "#82aeef"
13+
dark:
14+
color:
15+
palette:
16+
dark-grey: "#222"
17+
blue: "#415777"
18+
_quarto:
19+
tests:
20+
typst:
21+
ensureTypstFileRegexMatches:
22+
-
23+
- 'blue: rgb\("#82aeef"\)'
24+
- 'light-grey: rgb\("#444"\)'
25+
- '#set text\(fill: brand-color\.blue\);'
26+
-
27+
printsMessage:
28+
level: INFO
29+
regex: 'unknown brand color dark-grey'
30+
---
31+
32+
33+
```{=typst}
34+
// stopgap to make this look ok
35+
#set block(inset: 6pt)
36+
```
37+
38+
:::{style="background-color: var(--brand-dark-grey); color: var(--brand-blue)"}
39+
This div is blue on dark grey.
40+
:::
41+
42+
{{< lipsum 2 >}}

0 commit comments

Comments
 (0)