Description Usage Arguments Details Value Examples
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.
1 2 3 4 5 6 7 8 |
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()
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | 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])
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.