Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
28 changes: 24 additions & 4 deletions src/resources/extensions/quarto/kbd/kbd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,30 @@ return {
end

return pandoc.RawInline('html', '<kbd aria-hidden="true" ' .. kwargs_str .. '>' .. default_arg_str .. '</kbd><span class="visually-hidden">' .. default_arg_str .. '</span>')
elseif quarto.doc.isFormat("asciidoc") and args and #args == 1 then
-- get the 'first' kbd shortcut as we can only produce on shortcut in asciidoc
local shortcutText = pandoc.utils.stringify(args[1]):gsub('-', '+')
return pandoc.RawInline("asciidoc", "kbd:[" .. shortcutText .. "]")
elseif quarto.doc.isFormat("asciidoc") then
if args and #args == 1 then
-- https://docs.asciidoctor.org/asciidoc/latest/macros/keyboard-macro/

-- get the 'first' kbd shortcut as we can only produce one shortcut in asciidoc
local shortcutText = pandoc.utils.stringify(args[1]):gsub('-', '+')

-- from the docs:
-- If the last key is a backslash (\), it must be followed by a space.
-- Without this space, the processor will not recognize the macro.
-- If one of the keys is a closing square bracket (]), it must be preceded by a backslash.
-- Without the backslash escape, the macro will end prematurely.

if shortcutText:sub(-1) == "\\" then
shortcutText = shortcutText .. " "
end
if shortcutText:find("]") then
shortcutText = shortcutText:gsub("]", "\\]")
end

return pandoc.RawInline("asciidoc", "kbd:[" .. shortcutText .. "]")
else
return quarto.shortcode.error_output("kbd", "kbd only supports one positional argument", "inline")
end
else
-- example shortcodes
-- {{< kbd Shift-Ctrl-P >}}
Expand Down
5 changes: 5 additions & 0 deletions tests/docs/smoke-all/2025/04/09/kbd-adoc-bad-input.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
format: asciidoc
---

{{< kbd key="\\" >}}
Loading