Skip to content

Commit 3c45aed

Browse files
committed
brand,lua - color API (module, shortcodes)
1 parent 8201ef0 commit 3c45aed

File tree

2 files changed

+42
-14
lines changed

2 files changed

+42
-14
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- brand.lua
2+
-- Copyright (C) 2020-2024 Posit Software, PBC
3+
4+
local function get_color(name)
5+
local brand = param("brand").processedData -- from src/core/brand/brand.ts
6+
return brand.color[name]
7+
end
8+
9+
return {
10+
get_color = get_color
11+
}

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

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,20 @@ end
5959

6060
local handlers = {}
6161

62+
local function read_arg(args, n)
63+
local arg = args[n or 1]
64+
local varName
65+
if arg == nil then
66+
return nil
67+
end
68+
if type(arg) ~= "string" then
69+
varName = inlinesToString(arg)
70+
else
71+
varName = arg
72+
end
73+
return varName
74+
end
75+
6276
function initShortcodeHandlers()
6377

6478
-- user provided handlers
@@ -90,32 +104,35 @@ function initShortcodeHandlers()
90104
end)
91105
end
92106

107+
local function handle_brand(args)
108+
local brand = require("modules/brand/brand")
109+
local brandCommand = read_arg(args, 1)
110+
if brandCommand ~= "color" then
111+
warn("Unknown brand command " .. brandCommand .. " specified in a brand shortcode.")
112+
return { pandoc.Strong({pandoc.Str("?brand:" .. brandCommand)}) }
113+
end
114+
local brandName = read_arg(args, 2)
115+
local brandValue = brand.get_color(brandName)
116+
if brandValue ~= nil then
117+
return { pandoc.Str(brandValue) }
118+
else
119+
warn("Unknown brand " .. brandName .. " specified in a brand shortcode.")
120+
return { pandoc.Strong({pandoc.Str("?brand:" .. brandName)}) }
121+
end
122+
end
93123

94124
-- built in handlers (these override any user handlers)
95125
handlers['meta'] = { handle = handleMeta }
96126
handlers['var'] = { handle = handleVars }
97127
handlers['env'] = { handle = handleEnv }
98128
handlers['pagebreak'] = { handle = handlePagebreak }
129+
handlers['brand'] = { handle = handle_brand }
99130
end
100131

101132
function handlerForShortcode(shortCode)
102133
return handlers[shortCode.name]
103134
end
104135

105-
local function read_arg(args, n)
106-
local arg = args[n or 1]
107-
local varName
108-
if arg == nil then
109-
return nil
110-
end
111-
if type(arg) ~= "string" then
112-
varName = inlinesToString(arg)
113-
else
114-
varName = arg
115-
end
116-
return varName
117-
end
118-
119136
-- Implements reading values from envrionment variables
120137
function handleEnv(args)
121138
if #args > 0 then

0 commit comments

Comments
 (0)