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!" )
| 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. |
An HTML tag object that can be rendered as HTML using
as.character().
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).
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] ) if (FALSE) { rmarkdown::render(tf[1], "html_document", tf[2]) browseURL(paste0("file://", tf[2]))}