Skip to content
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

improve tooltip readability and add opt-in tooltip for footnotes #68

Open
wants to merge 2 commits into
base: master
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
6 changes: 5 additions & 1 deletion R/mini-document.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#' @param results_folding Setup results folding by a string, `"none"`, `"show"`,
#' or `"hide"`. This feature will fold entire results, including side effects
#' such as figures and tables.
#' @param footenote_tooltip `TRUE` let footnotes to be also shown as tooltips.
#' @param tabset `TRUE` converts sections to tabs if they belong to the
#' `tabset`-class section. The tabs inherit names from the corresponding
#' sections. Unlike `rmarkdown::html_document`, the tabs can be navigated by
Expand Down Expand Up @@ -59,6 +60,7 @@ mini_document <- function(framework = "sakura",
section_divs = TRUE,
code_folding = c("none", "show", "hide"),
results_folding = c("none", "show", "hide"),
footnote_tooltip = FALSE,
tabset = FALSE,
code_download = FALSE,
self_contained = TRUE,
Expand All @@ -81,7 +83,9 @@ mini_document <- function(framework = "sakura",

fmt <- rmarkdown::html_document(
theme = if (html5) NULL else theme,
pandoc_args = spec_pandoc_args(pandoc_args, html5, katex),
pandoc_args = spec_pandoc_args(
pandoc_args, html5, katex, footnote_tooltip
),
extra_dependencies = spec_dependencies(
extra_dependencies,
html5 = html5,
Expand Down
1 change: 0 additions & 1 deletion R/spec-dependencies.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ spec_dependencies <- function(extra_dependencies = NULL,
paste0(`if`(all_frameworks, default_framework, framework), ".css")
},
"common.css",
if (with_framework && framework != "mini") "feat-tooltip.css",
if (toc_float) "feat-toc-float.css"
),
meta = if (all_frameworks) {
Expand Down
20 changes: 11 additions & 9 deletions R/spec-pandoc-args.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
#' @noRd
spec_pandoc_args <- function(pandoc_args = NULL,
html5 = TRUE,
katex = TRUE) {

katex = TRUE,
footnote_tooltip = FALSE) {
lua <- if (check_pandoc_version(minimum = "2.0.0", recommend = "2.7.2")) {
if (html5) {
dir(path_mini_resources("lua"), pattern = "\\.lua$", full.names = TRUE)
} else {
path_mini_resources("lua", "code-folding.lua")
}
} else {
character(0L)
path_mini_resources(
"lua",
c(
if (html5) "tooltip.lua",
if (footnote_tooltip) "footnote-tooltip.lua",
"code-folding.lua"
)
)
}

c(
Expand All @@ -20,3 +21,4 @@ spec_pandoc_args <- function(pandoc_args = NULL,
if (katex) "--mathjax"
)
}

1 change: 1 addition & 0 deletions docs/index.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ output:
toc: true
toc_float: true
toc_highlight: true
footnote_tooltip: true
tabset: true
number_sections: true
anchor_sections: false
Expand Down
63 changes: 0 additions & 63 deletions inst/rmarkdown/html/styles/feat-tooltip.css

This file was deleted.

4 changes: 4 additions & 0 deletions inst/rmarkdown/lua/footnote-tooltip.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function Note(note)
return pandoc.Span(note, {title = pandoc.utils.stringify(note.content)})
end

21 changes: 12 additions & 9 deletions inst/rmarkdown/lua/tooltip.lua
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
--wip: remove elem.attr.attributes.tooltip

function Span(elem)
local tooltip = elem.attributes and elem.attributes.tooltip
if tooltip then
return {
pandoc.RawInline(
"html", '<span class=tooltip aria-label="' .. tooltip .. '">'
),
elem,
pandoc.RawInline("html", "</span>")
}
local tooltip_str = pandoc.utils.stringify(tooltip)
local attributes = {}
attributes["aria-label"] = tooltip_str
attributes["title"] = tooltip_str
for k,v in pairs(elem.attributes) do
if k ~= "tooltip" then
attributes[k] = v
end
end
elem.attributes = attributes
return elem
end
end

10 changes: 7 additions & 3 deletions man/mini_document.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.