@@ -32,10 +32,30 @@ return {
3232 end
3333
3434 return pandoc .RawInline (' html' , ' <kbd aria-hidden="true" ' .. kwargs_str .. ' >' .. default_arg_str .. ' </kbd><span class="visually-hidden">' .. default_arg_str .. ' </span>' )
35- elseif quarto .doc .isFormat (" asciidoc" ) and args and # args == 1 then
36- -- get the 'first' kbd shortcut as we can only produce on shortcut in asciidoc
37- local shortcutText = pandoc .utils .stringify (args [1 ]):gsub (' -' , ' +' )
38- return pandoc .RawInline (" asciidoc" , " kbd:[" .. shortcutText .. " ]" )
35+ elseif quarto .doc .isFormat (" asciidoc" ) then
36+ if args and # args == 1 then
37+ -- https://docs.asciidoctor.org/asciidoc/latest/macros/keyboard-macro/
38+
39+ -- get the 'first' kbd shortcut as we can only produce one shortcut in asciidoc
40+ local shortcutText = pandoc .utils .stringify (args [1 ]):gsub (' -' , ' +' )
41+
42+ -- from the docs:
43+ -- If the last key is a backslash (\), it must be followed by a space.
44+ -- Without this space, the processor will not recognize the macro.
45+ -- If one of the keys is a closing square bracket (]), it must be preceded by a backslash.
46+ -- Without the backslash escape, the macro will end prematurely.
47+
48+ if shortcutText :sub (- 1 ) == " \\ " then
49+ shortcutText = shortcutText .. " "
50+ end
51+ if shortcutText :find (" ]" ) then
52+ shortcutText = shortcutText :gsub (" ]" , " \\ ]" )
53+ end
54+
55+ return pandoc .RawInline (" asciidoc" , " kbd:[" .. shortcutText .. " ]" )
56+ else
57+ return quarto .shortcode .error_output (" kbd" , " kbd only supports one positional argument" , " inline" )
58+ end
3959 else
4060 -- example shortcodes
4161 -- {{< kbd Shift-Ctrl-P >}}
0 commit comments