Skip to content

Commit d9a3db2

Browse files
authored
Merge pull request #13085 from quarto-dev/bugfix/kbd-crash
kbd - don't crash on unknown os keys
2 parents 67d10e9 + 9dcd2f8 commit d9a3db2

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

news/changelog-1.8.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,10 @@ All changes included in 1.8:
132132
- ([#12853](https://github.com/quarto-dev/quarto-cli/issues/12853)): fix replaceAll() escaping issue with embedded notebooks containing `$` in their Markdown.
133133
- ([#12939](https://github.com/quarto-dev/quarto-cli/pull/12939)): Upgrade `mermaidjs` to 11.6.0.
134134
- ([#13031](https://github.com/quarto-dev/quarto-cli/pull/13031)): Add `.quarto_ipynb` files to `.gitignore` by default.
135+
- ([#13085](https://github.com/quarto-dev/quarto-cli/pull/13085)): Avoid `kbd` shortcode crashes on unknown OS keys.
135136
- ([#13164](https://github.com/quarto-dev/quarto-cli/pull/13164)): add `julia` to execute schema to allow autocomplete suggestions. (@mcanouil)
136137

138+
137139
## Quarto Internals
138140

139141
- ([#13155](https://github.com/quarto-dev/quarto-cli/pull/13155)): Process `pandoc-reader-FORMAT` raw blocks through `pandoc.read(FORMAT)`

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

Lines changed: 10 additions & 5 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)
@@ -78,7 +83,7 @@ return {
7883
if n_kwargs > 0 then
7984
table.insert(result, pandoc.Str(' ('))
8085
for k, v in pairs(kwargs) do
81-
table.insert(result, pandoc.Str(osname(k)))
86+
table.insert(result, pandoc.Str(get_osname(k)))
8287
table.insert(result, pandoc.Str(': '))
8388
table.insert(result, pandoc.Code(pandoc.utils.stringify(v)))
8489
n_kwargs = n_kwargs - 1
@@ -98,7 +103,7 @@ return {
98103
for k, v in pairs(kwargs) do
99104
table.insert(result, pandoc.Code(pandoc.utils.stringify(v)))
100105
table.insert(result, pandoc.Str(' ('))
101-
table.insert(result, pandoc.Str(osname(k)))
106+
table.insert(result, pandoc.Str(get_osname(k)))
102107
table.insert(result, pandoc.Str(')'))
103108
n_kwargs = n_kwargs - 1
104109
if n_kwargs > 0 then
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)