Title: | Copy to Clipboard Buttons for R Markdown HTML Documents |
---|---|
Description: | Insert copy to clipboard buttons in HTML documents generated with 'rmarkdown'. This package is suited for a call in a 'knitr' chunk. Buttons events are rendered using 'clipboard.js' library and 'Bootstrap.js' Tooltip plugin. |
Authors: | Romain Lesur [aut, cre] , Zeno Rocha [cph] (clipboard.js library), GitHub, Inc. [cph] (Primer Tooltips library & Octicons library) |
Maintainer: | Romain Lesur <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.0.0.9500 |
Built: | 2024-11-06 05:12:29 UTC |
Source: | https://github.com/rlesur/klippy |
These functions provide HTML dependencies for clipboard.js
,
klippy
and Primer Tooltips CSS
for re-use.
html_dependency_clipboard() html_dependency_primer_tooltips() html_dependency_klippy()
html_dependency_clipboard() html_dependency_primer_tooltips() html_dependency_klippy()
An object that can be included in a list of dependencies passed to htmltools::attachDependencies().
Other HTML dependencies functions:
klippy_dependencies()
klippy
insert copy to clipboard buttons (or "klippies") in R
Markdown
HTML
documents. In the rendered document, "klippies"
are inserted in the upper left corner of the code chunks. klippy()
function is suited for a call in a knitr
code chunk.
klippy( lang = c("r", "markdown"), all_precode = FALSE, position = c("top", "left"), color = "auto", tooltip_message = "Copy code", tooltip_success = "Copied!" )
klippy( lang = c("r", "markdown"), all_precode = FALSE, position = c("top", "left"), color = "auto", tooltip_message = "Copy code", tooltip_success = "Copied!" )
lang |
A character string or a vector of character strings with
language names. If a character string contains multiple languages
names, these names have to be separated by boundaries (e.g., spaces).
Void string can be passed to |
all_precode |
A logical scalar. If |
position |
A character vector with |
color |
String of any of the three kinds of |
tooltip_message |
String with the tooltip message. |
tooltip_success |
String with the tooltip message shown when code is successfully copied. |
klippy()
function appends JavaScript
functions and CSS
in
the rendered document that:
Add klippy
to the class attribute of selected <pre>
elements.
Add a <button>
element (a "klippy") as a child for all
<pre>
elements with a klippy
class attribute.
Instantiate clipboard.js
event listeners and attach them to
klippies
.
klippy
class can also be appended to a <pre>
element using
knitr class.source
chunk option. "Klippy" buttons are not rendered if the browser does not support
clipboard.js
library (see here for
details).
An HTML tag object that can be rendered as HTML using
as.character()
.
tf <- tempfile(fileext = c(".Rmd", ".html")) writeLines( c("```{r klippy, echo=FALSE, include=TRUE}", "klippy::klippy()", "```", "Insert this chunk in your `Rmd` file:", "````markdown", "`r ''````{r klippy, echo=FALSE, include=TRUE}", "klippy::klippy()", "```", "````" ), tf[1] ) rmarkdown::render(tf[1], "html_document", tf[2])
tf <- tempfile(fileext = c(".Rmd", ".html")) writeLines( c("```{r klippy, echo=FALSE, include=TRUE}", "klippy::klippy()", "```", "Insert this chunk in your `Rmd` file:", "````markdown", "`r ''````{r klippy, echo=FALSE, include=TRUE}", "klippy::klippy()", "```", "````" ), tf[1] ) rmarkdown::render(tf[1], "html_document", tf[2])
This function is used to get the list of klippy
dependencies.
klippy_dependencies()
klippy_dependencies()
A list of dependencies that can be passed to
htmltools::attachDependencies() or
rmarkdown::html_document_base()
.
Other HTML dependencies functions:
html_dependencies