Skip to content

kbd - don't crash on unknown os keys #13085

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/changelog-1.8.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,4 @@ All changes included in 1.8:
- ([#12782](https://github.com/quarto-dev/quarto-cli/pull/12782)): fix bug on `safeRemoveDirSync`'s detection of safe directory boundaries.
- ([#12853](https://github.com/quarto-dev/quarto-cli/issues/12853)): fix replaceAll() escaping issue with embedded notebooks containing `$` in their Markdown.
- ([#12939](https://github.com/quarto-dev/quarto-cli/pull/12939)): Upgrade `mermaidjs` to 11.6.0.
- ([#13085](https://github.com/quarto-dev/quarto-cli/pull/13085)): Avoid `kbd` shortcode crashes on unknown OS keys.
11 changes: 8 additions & 3 deletions src/resources/extensions/quarto/kbd/kbd.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-- todo: i18n :(
return {
['kbd'] = function(args, kwargs, meta)
local function osname(v)
local function get_osname(v)
if v == "win" then return "windows" end
if v == "mac" then return "mac" end
if v == "linux" then return "linux" end
Expand All @@ -15,8 +15,13 @@ return {
local kwargs_strs = {}
local title_strs = {}
for k, v in pairs(kwargs) do
table.insert(kwargs_strs, string.format('data-%s="%s"', osname(k), pandoc.utils.stringify(v)))
table.insert(title_strs, osname(k) .. ': ' .. pandoc.utils.stringify(v))
local osname = get_osname(k)
if osname == nil then
quarto.log.warning("unknown os name in kbd shortcode: " .. k .. ", supported names are: win, mac, linux")
return quarto.shortcode.error_output("kbd", "unknown os name: " .. k, "inline")
end
table.insert(kwargs_strs, string.format('data-%s="%s"', osname, pandoc.utils.stringify(v)))
table.insert(title_strs, osname .. ': ' .. pandoc.utils.stringify(v))
end
table.sort(kwargs_strs) -- sort so that the output is deterministic
local kwargs_str = table.concat(kwargs_strs)
Expand Down
6 changes: 6 additions & 0 deletions tests/docs/smoke-all/2025/07/16/kbd-crash.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
format: html
---

{{< kbd windows=alt-f4 >}}

Loading