Skip to content

Commit eec03d4

Browse files
brand logo shortcode: automatic light and dark classes
and include both if no brand-mode specified also use alt text from brand logo spec fixes #13004
1 parent d0d88b6 commit eec03d4

12 files changed

+195
-32
lines changed

news/changelog-1.8.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ All changes included in 1.8:
2929
- ([#12797](https://github.com/quarto-dev/quarto-cli/issues/12797)): Allow light and dark brands to be specified in one file, by specializing colors with `light:` and `dark:`.
3030
- ([#12919](https://github.com/quarto-dev/quarto-cli/issues/12919)): Ensure `kbd` shortcode output has hover tooltip.
3131
- ([#12981](https://github.com/quarto-dev/quarto-cli/issues/12981)): Brand should be applied in dark mode when dark mode is enabled by the theme, not the brand.
32+
- ([#13004](https://github.com/quarto-dev/quarto-cli/issues/13004)): Brand logo shortcode automatically applies `.light-content` and `.dark-content` classes, inserts both light and dark logo if brand mode is not specified, and uses alt text from brand logo spec.
3233

3334
### `revealjs`
3435

src/resources/filters/quarto-pre/shortcodes-handlers.lua

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -127,41 +127,57 @@ function initShortcodeHandlers()
127127
end
128128

129129
if brandCommand == "logo" then
130-
local logo_name = read_arg(args, 2)
131-
local brandMode = 'light'
130+
local logoName = read_arg(args, 2)
131+
local brandMode = 'both'
132132
if #args > 2 then
133133
brandMode = read_arg(args, 3) or brandMode
134134
end
135-
local logo_value = brand.get_logo(brandMode, logo_name)
136-
local entry = { path = nil }
137-
138-
if type(logo_value) ~= "table" then
139-
warn("unexpected logo value entry: " .. type(logo_value))
140-
return warn_bad_brand_command()
135+
local lightLogo, darkLogo
136+
if brandMode == 'light' or brandMode == 'both' then
137+
lightLogo = brand.get_logo('light', logoName) or brand.get_logo('dark', logoName)
138+
if lightLogo then
139+
if type(lightLogo) ~= "table" then
140+
warn("unexpected light logo type: " .. type(lightLogo))
141+
return warn_bad_brand_command()
142+
end
143+
if type(lightLogo.path) ~= "string" then
144+
warn("unexpected light logo path type: " .. type(lightLogo.path))
145+
return warn_bad_brand_command()
146+
end
147+
end
141148
end
142-
143-
quarto.utils.dump(logo_value)
144-
145-
-- does this have light/dark variants?
146-
-- TODO handle light-dark theme switching
147-
if logo_value.light then
148-
entry = logo_value.light
149-
else
150-
entry = logo_value
149+
if brandMode == 'dark' or brandMode == 'both' then
150+
-- fall back to light logo only if explicit dark logo or dark mode is enabled
151+
darkLogo = brand.get_logo('dark', logoName) or
152+
((brandMode == 'dark' or brand.has_mode('dark')) and brand.get_logo('light', logoName))
153+
if darkLogo then
154+
if type(darkLogo) ~= "table" then
155+
warn("unexpected dark logo type: " .. type(darkLogo))
156+
return warn_bad_brand_command()
157+
end
158+
if type(darkLogo.path) ~= "string" then
159+
warn("unexpected dark logo path type: " .. type(darkLogo.path))
160+
return warn_bad_brand_command()
161+
end
162+
end
151163
end
152-
153-
if type(entry.path) ~= "string" then
154-
warn("unexpected type in logo light entry: " .. type(entry.path))
155-
return warn_bad_brand_command()
164+
if context == "text" then
165+
-- 'both' would not make sense here
166+
return lightLogo and lightLogo.path or darkLogo and darkLogo.path
167+
end
168+
local images = {}
169+
if lightLogo then
170+
table.insert(images, pandoc.Image(pandoc.Inlines {}, lightLogo.path, "",
171+
pandoc.Attr("", {"light-content"}, {alt = lightLogo.alt})))
172+
end
173+
if darkLogo then
174+
table.insert(images, pandoc.Image(pandoc.Inlines {}, darkLogo.path, "",
175+
pandoc.Attr("", {"dark-content"}, {alt = darkLogo.alt})))
156176
end
157-
158-
-- TODO fix alt text handling
159177
if context == "block" then
160-
return pandoc.Blocks { pandoc.Image(pandoc.Inlines {}, entry.path) }
178+
return pandoc.Blocks(images)
161179
elseif context == "inline" then
162-
return pandoc.Inlines { pandoc.Image(pandoc.Inlines {}, entry.path) }
163-
elseif context == "text" then
164-
return entry.path
180+
return pandoc.Inlines(images)
165181
else
166182
warn("unexpected context for logo shortcode: " .. context)
167183
return warn_bad_brand_command()
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
title: Test brand light/dark shortcodes
3+
format: html
4+
brand:
5+
light:
6+
logo:
7+
images:
8+
sun:
9+
path: sun.png
10+
alt: sun
11+
small: sun
12+
dark:
13+
logo:
14+
images:
15+
moon:
16+
path: moon.png
17+
alt: moon
18+
small: moon
19+
_quarto:
20+
tests:
21+
html:
22+
ensureHtmlElements:
23+
-
24+
- 'img[src="sun.png"][alt="sun"][class*="light-content"]'
25+
- 'img[src="moon.png"][alt="moon"][class*="dark-content"]'
26+
- []
27+
---
28+
29+
::: {}
30+
31+
{{< brand logo small >}}
32+
33+
:::

tests/docs/shortcodes/brand-logo-dark.qmd renamed to tests/docs/smoke-all/shortcodes/brand-logo-dark.qmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ _quarto:
1313
html:
1414
ensureHtmlElements:
1515
-
16-
- 'img[src="moon.png"]'
16+
- 'img[src="moon.png"][class*="dark-content"]'
1717
- []
1818
---
1919

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
title: Test brand logo light fallback behavior
3+
format: html
4+
brand:
5+
dark:
6+
logo:
7+
small: dark-logo.png
8+
medium: dark-medium-logo.png
9+
# No light logo specified
10+
_quarto:
11+
tests:
12+
html:
13+
ensureHtmlElements:
14+
-
15+
# When requesting dark mode explicitly, should get dark logo
16+
- 'img[src="dark-logo.png"][class*="dark-content"]'
17+
# When requesting light mode explicitly (which doesn't exist), should fall back to dark logo but with light-content class
18+
- 'img[src="dark-logo.png"][class*="light-content"]'
19+
# When requesting medium size with light mode (doesn't exist), should fall back to dark-medium with light-content class
20+
- 'img[src="dark-medium-logo.png"][class*="light-content"]'
21+
- []
22+
---
23+
24+
### Dark Logo (Dark Mode)
25+
{{< brand logo small dark >}}
26+
27+
### Dark Logo (Light Mode - should fall back)
28+
{{< brand logo small light >}}
29+
30+
### Medium Logo (Light Mode - should fall back)
31+
{{< brand logo medium light >}}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
title: Test brand logo dark fallback behavior
3+
format: html
4+
brand:
5+
light:
6+
logo:
7+
small: light-logo.png
8+
medium: light-medium-logo.png
9+
# No dark logo specified
10+
_quarto:
11+
tests:
12+
html:
13+
ensureHtmlElements:
14+
-
15+
# When requesting light mode explicitly, should get light logo
16+
- 'img[src="light-logo.png"][class*="light-content"]'
17+
# When requesting dark mode explicitly (which doesn't exist), should fall back to light logo but with dark-content class
18+
- 'img[src="light-logo.png"][class*="dark-content"]'
19+
# When requesting medium size with dark mode (doesn't exist), should fall back to light-medium with dark-content class
20+
- 'img[src="light-medium-logo.png"][class*="dark-content"]'
21+
- []
22+
---
23+
24+
### Light Logo (Light Mode)
25+
{{< brand logo small light >}}
26+
27+
### Light Logo (Dark Mode - should fall back)
28+
{{< brand logo small dark >}}
29+
30+
### Medium Logo (Dark Mode - should fall back)
31+
{{< brand logo medium dark >}}

tests/docs/shortcodes/brand-logo-light.qmd renamed to tests/docs/smoke-all/shortcodes/brand-logo-light.qmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ _quarto:
1313
html:
1414
ensureHtmlElements:
1515
-
16-
- 'img[src="sun.png"]'
16+
- 'img[src="sun.png"][class*="light-content"]'
1717
- []
1818
---
1919

2020
::: {}
2121

22-
{{< brand logo small >}}
22+
{{< brand logo small light >}}
2323

2424
:::
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
title: Test brand logo size variants
3+
format: html
4+
brand:
5+
logo:
6+
small: small-logo.png
7+
medium: medium-logo.png
8+
large: large-logo.png
9+
_quarto:
10+
tests:
11+
html:
12+
ensureHtmlElements:
13+
-
14+
- 'img[src="small-logo.png"]'
15+
- 'img[src="medium-logo.png"]'
16+
- 'img[src="large-logo.png"]'
17+
- []
18+
---
19+
20+
### Small Logo
21+
{{< brand logo small >}}
22+
23+
### Medium Logo
24+
{{< brand logo medium >}}
25+
26+
### Large Logo
27+
{{< brand logo large >}}

tests/docs/shortcodes/brand-logo-one-brand.qmd renamed to tests/docs/smoke-all/shortcodes/brand-logo-unified-brand-nodark.qmd

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ _quarto:
99
html:
1010
ensureHtmlElements:
1111
-
12-
- 'img[src="sun.png"]'
13-
- []
12+
- 'img[src="sun.png"][class*="light-content"]'
13+
-
14+
- 'img[class*="dark-content"]'
1415
---
1516

1617

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
title: Test brand light/dark shortcodes
3+
format: html
4+
brand:
5+
logo:
6+
small: sun.png
7+
color:
8+
background:
9+
light: '#fff'
10+
dark: '#000'
11+
_quarto:
12+
tests:
13+
html:
14+
ensureHtmlElements:
15+
-
16+
- 'img[src="sun.png"][class*="light-content"]'
17+
- 'img[src="sun.png"][class*="dark-content"]'
18+
- []
19+
---
20+
21+
22+
{{< brand logo small >}}
23+

0 commit comments

Comments
 (0)