Skip to content

Commit b724667

Browse files
committed
kbd - don't crash on unknown os keys
1 parent 2f24776 commit b724667

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/resources/extensions/quarto/kbd/kbd.lua

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-- todo: i18n :(
22
return {
33
['kbd'] = function(args, kwargs, meta)
4-
local function osname(v)
4+
local function get_osname(v)
55
if v == "win" then return "windows" end
66
if v == "mac" then return "mac" end
77
if v == "linux" then return "linux" end
@@ -15,8 +15,13 @@ return {
1515
local kwargs_strs = {}
1616
local title_strs = {}
1717
for k, v in pairs(kwargs) do
18-
table.insert(kwargs_strs, string.format('data-%s="%s"', osname(k), pandoc.utils.stringify(v)))
19-
table.insert(title_strs, osname(k) .. ': ' .. pandoc.utils.stringify(v))
18+
local osname = get_osname(k)
19+
if osname == nil then
20+
quarto.log.warning("unknown os name in kbd shortcode: " .. k .. ", supported names are: win, mac, linux")
21+
return quarto.shortcode.error_output("kbd", "unknown os name: " .. k, "inline")
22+
end
23+
table.insert(kwargs_strs, string.format('data-%s="%s"', osname, pandoc.utils.stringify(v)))
24+
table.insert(title_strs, osname .. ': ' .. pandoc.utils.stringify(v))
2025
end
2126
table.sort(kwargs_strs) -- sort so that the output is deterministic
2227
local kwargs_str = table.concat(kwargs_strs)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
format: html
3+
---
4+
5+
{{< kbd windows=alt-f4 >}}
6+

0 commit comments

Comments
 (0)