--- title: "Insert copy to clipboard buttons in RMarkdown HTML documents" author: "Romain Lesur" date: "`r Sys.Date()`" output: prettydoc::html_pretty: theme: hpstr highlight: github pdf_document: default vignette: > %\VignetteIndexEntry{Insert copy to clipboard buttons in HTML documents} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r klippy, echo=FALSE, include=TRUE} klippy::klippy('') ``` ## Common use The `klippy` package enhances `R Markdown` `HTML` documents with **copy to clipboard buttons**. You only have to paste the following chunk anywhere in your `Rmd` file. Obviously, **you have to try the clipboard button in the upper left corner of this chunk!** ````{#ex .markdown .klippy} `r ''````{r klippy, echo=FALSE, include=TRUE} klippy::klippy() ``` ```` The `klippy()` function inserts a klippy[^1] in each `R` or `markdown` code block. ## Code block selection You can select which of the code blocks get a klippy. First, insert this chunk anywhere in your `Rmd` file: ````{#code-block-ex .markdown .klippy} `r ''````{r klippy, echo=FALSE, include=TRUE} klippy::klippy('') ``` ```` Then, add the `klippy` class to a code chunk: ````{.markdown} `r ''````{r cars, class.source='klippy'} summary(cars) ``` ```` ## Engine selection If you use other languages than `R` in your `Rmd` file, you can also add klippies to these code blocks. For example, if you want to add klippies to `R` and `python` code blocks, add this chunk anywhere in your `Rmd` file: ````{.markdown .klippy} `r ''````{r klippy, echo=FALSE, include=TRUE} klippy::klippy(c('r', 'python')) ``` ```` ## Icon positioning By default, `klippy` is positionned at the upper-left corner of the code chunks. You can choose another corner with `position` argument: ````{.markdown .klippy} `r ''````{r klippy, echo=FALSE, include=TRUE} klippy::klippy(position = c('top', 'right')) ``` ```` ## Color customization `klippy` color is the same as the links in the document. However, you can pick another color: ````{.markdown .klippy} `r ''````{r klippy, echo=FALSE, include=TRUE} klippy::klippy(color = 'darkred') ``` ```` ## Tooltip messages Tooltip messages can also be adapted: ````{.markdown .klippy} `r ''````{r klippy, echo=FALSE, include=TRUE} klippy::klippy(tooltip_message = 'Click to copy', tooltip_success = 'Done') ``` ```` ## Browser Support For supported browsers, see [`clipboard.js` documentation](https://clipboardjs.com/#browser-support). [^1]: A klippy is a knitweaR clipboard button.