Skip to content

Commit 3b2ae35

Browse files
authored
Merge pull request #11140 from quarto-dev/feature/brand-yaml-shortcode-logo
brand,logo,lua - add support for resolving logo images in brand short…
2 parents 636ce93 + efd6eb1 commit 3b2ae35

File tree

4 files changed

+79
-14
lines changed

4 files changed

+79
-14
lines changed

src/core/brand/brand.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,12 @@ type CanonicalLogoInfo = {
5151
type ProcessedBrandData = {
5252
color: Record<string, string>;
5353
typography: BrandTypography;
54-
logo: Record<string, CanonicalLogoInfo>;
54+
logo: {
55+
small?: CanonicalLogoInfo;
56+
medium?: CanonicalLogoInfo;
57+
large?: CanonicalLogoInfo;
58+
images: Record<string, BrandLogoExplicitResource>;
59+
};
5560
};
5661

5762
export class Brand {
@@ -139,7 +144,7 @@ export class Brand {
139144
};
140145
}
141146

142-
const logo: Record<string, CanonicalLogoInfo> = {};
147+
const logo: ProcessedBrandData["logo"] = { images: {} };
143148
for (
144149
const size of [
145150
"small",
@@ -151,6 +156,13 @@ export class Brand {
151156
if (v) {
152157
logo[size] = v;
153158
}
159+
for (const [key, value] of Object.entries(data.logo?.images ?? {})) {
160+
if (typeof value === "string") {
161+
logo.images[key] = { path: value };
162+
} else {
163+
logo.images[key] = value;
164+
}
165+
}
154166
}
155167

156168
return {

src/format/reveal/format-reveal.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,9 @@ export function revealjsFormat() {
379379
const determineRevealLogo = (format: Format): string | undefined => {
380380
const brandData = format.render.brand?.processedData;
381381
if (brandData?.logo) {
382+
const keys: ("medium" | "small" | "large")[] = ["medium", "small", "large"]
382383
// add slide logo if we have one
383-
for (const size of ["medium", "small", "large"]) {
384+
for (const size of keys) {
384385
const logoInfo = brandData.logo[size];
385386
if (!logoInfo) {
386387
continue;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ local function get_logo(name)
5656
local brand = param("brand")
5757
brand = brand and brand.processedData -- from src/core/brand/brand.ts
5858
if not brand then return nil end
59-
return brand.logo and brand.logo[name]
59+
return brand.logo and (brand.logo[name] or brand.logo.images[name])
6060
end
6161

6262
return {

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

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,21 +115,73 @@ function initShortcodeHandlers()
115115
return { pandoc.RawInline('quarto-internal', quarto.json.encode(data)) }
116116
end
117117

118-
local function handle_brand(args)
118+
local function handle_brand(args, _kwargs, _meta, _raw_args, context)
119119
local brand = require("modules/brand/brand")
120120
local brandCommand = read_arg(args, 1)
121-
if brandCommand ~= "color" then
121+
122+
local warn_bad_brand_command = function()
122123
warn("Unknown brand command " .. brandCommand .. " specified in a brand shortcode.")
123-
return { pandoc.Strong({pandoc.Str("?brand:" .. brandCommand)}) }
124+
if context == "block" then
125+
return pandoc.Blocks { pandoc.Strong({pandoc.Str("?brand:" .. table.concat(args, " "))}) }
126+
elseif context == "inline" then
127+
return pandoc.Inlines { pandoc.Strong({pandoc.Str("?brand:" .. table.concat(args, " "))}) }
128+
elseif context == "text" then
129+
return "?brand:" .. table.concat(args, " ")
130+
else
131+
warn("Unknown context for brand shortcode error: " .. context)
132+
return { }
133+
end
124134
end
125-
local brandName = read_arg(args, 2)
126-
local brandValue = brand.get_color(brandName)
127-
if brandValue ~= nil then
128-
return { pandoc.Str(brandValue) }
129-
else
130-
warn("Unknown brand " .. brandName .. " specified in a brand shortcode.")
131-
return { pandoc.Strong({pandoc.Str("?brand:" .. brandName)}) }
135+
136+
if brandCommand == "color" then
137+
local color_name = read_arg(args, 2)
138+
local color_value = brand.get_color(color_name)
139+
if color_value == nil then
140+
return warn_bad_brand_command()
141+
else
142+
return pandoc.Inlines { pandoc.Str(color_value) }
143+
end
132144
end
145+
146+
if brandCommand == "logo" then
147+
local logo_name = read_arg(args, 2)
148+
local logo_value = brand.get_logo(logo_name)
149+
local entry = { path = nil }
150+
151+
if type(logo_value) ~= "table" then
152+
warn("unexpected logo value entry: " .. type(logo_value))
153+
return warn_bad_brand_command()
154+
end
155+
156+
quarto.utils.dump(logo_value)
157+
158+
-- does this have light/dark variants?
159+
-- TODO handle light-dark theme switching
160+
if logo_value.light then
161+
entry = logo_value.light
162+
else
163+
entry = logo_value
164+
end
165+
166+
if type(entry.path) ~= "string" then
167+
warn("unexpected type in logo light entry: " .. type(entry.path))
168+
return warn_bad_brand_command()
169+
end
170+
171+
-- TODO fix alt text handling
172+
if context == "block" then
173+
return pandoc.Blocks { pandoc.Image(pandoc.Inlines {}, entry.path) }
174+
elseif context == "inline" then
175+
return pandoc.Inlines { pandoc.Image(pandoc.Inlines {}, entry.path) }
176+
elseif context == "text" then
177+
return entry.path
178+
else
179+
warn("unexpected context for logo shortcode: " .. context)
180+
return warn_bad_brand_command()
181+
end
182+
end
183+
184+
return warn_bad_brand_command()
133185
end
134186

135187
-- built in handlers (these override any user handlers)

0 commit comments

Comments
 (0)