Skip to content

Commit 4b01fd8

Browse files
committed
kbd - emit hover tooltip in html (#12919)
1 parent ab22bb9 commit 4b01fd8

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

news/changelog-1.8.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ All changes included in 1.8:
2020
- ([#12747](https://github.com/quarto-dev/quarto-cli/issues/12747)): Ensure `th` elements are properly restored when Quarto's HTML table processing is happening.
2121
- ([#12766](https://github.com/quarto-dev/quarto-cli/issues/12766)): Use consistent equation numbering display for `html-math-method` and `html-math-method.method` for MathJax and KaTeX (author: @mcanouil)
2222
- ([#12797](https://github.com/quarto-dev/quarto-cli/issues/12797)): Allow light and dark brands to be specified in one file, by specializing colors with `light:` and `dark:`.
23+
- ([#12919](https://github.com/quarto-dev/quarto-cli/issues/12919)): Ensure `kbd` shortcode output has hover tooltip.
2324

2425
### `revealjs`
2526

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ return {
1313
stylesheets = { 'resources/kbd.css' }
1414
})
1515
local kwargs_strs = {}
16+
local title_strs = {}
1617
for k, v in pairs(kwargs) do
1718
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))
1820
end
1921
table.sort(kwargs_strs) -- sort so that the output is deterministic
2022
local kwargs_str = table.concat(kwargs_strs)
@@ -29,9 +31,14 @@ return {
2931
default_arg_str = ""
3032
else
3133
default_arg_str = pandoc.utils.stringify(args[1])
34+
table.insert(title_strs, default_arg_str)
3235
end
33-
34-
return pandoc.RawInline('html', '<kbd aria-hidden="true" ' .. kwargs_str .. '>' .. default_arg_str .. '</kbd><span class="visually-hidden">' .. default_arg_str .. '</span>')
36+
table.sort(title_strs) -- sort so that the output is deterministic
37+
local title_str = table.concat(title_strs, ', ')
38+
if title_str == "" then
39+
title_str = default_arg_str
40+
end
41+
return pandoc.RawInline('html', '<kbd title="' .. title_str .. '" aria-hidden="true" ' .. kwargs_str .. '>' .. default_arg_str .. '</kbd><span class="visually-hidden">' .. default_arg_str .. '</span>')
3542
elseif quarto.doc.isFormat("asciidoc") then
3643
if args and #args == 1 then
3744
-- https://docs.asciidoctor.org/asciidoc/latest/macros/keyboard-macro/
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
format: html
3+
_quarto:
4+
tests:
5+
html:
6+
ensureHtmlElements:
7+
- ['kbd[title="Shift-K"]','kbd[title="linux: Shift-Ctrl-L, mac: Shift-Command-O, windows: Shift-Control-O"]']
8+
---
9+
10+
{{< kbd mac=Shift-Command-O win=Shift-Control-O linux=Shift-Ctrl-L >}}
11+
12+
{{< kbd Shift-K >}}

0 commit comments

Comments
 (0)