clipboard {xaringanExtra} | R Documentation |
Clipboard
Description
Add a "Copy Code" button for one-click code chunk copying.
Usage
use_clipboard(
button_text = "Copy Code",
success_text = "Copied!",
error_text = "Press Ctrl+C to Copy",
selector = NULL,
minified = TRUE
)
html_dependency_clipboardjs(minified = TRUE)
html_dependency_clipboard()
Arguments
button_text , success_text , error_text |
Text (or HTML) shown in the copy button by default (button), on copy success, or in the event of an error. |
selector |
The CSS selector used to identify the elements that will
receive the copy code button. If The CSS selector should identify the parent container that holds the content to be copied. The copy button will be added as the last element in this container, and then the text of every element inside the container identified by the selector, minus the copy button text, is copied to the clipboard. |
minified |
Should the minified clipboardjs dependency be used? |
Details
To add clipboard to your xaringan presentation or R Markdown document, add the following code chunk to your slides’ R Markdown file.
```{r xaringanExtra-clipboard, echo=FALSE} xaringanExtra::use_clipboard() ```
You can also customize the text that is shown by default when hovering
over a code chunk with the button_text
argument. Use success_text
to
specify the text shown when the copy action works, or error_text
for
the text shown when the copy action fails. If the copy action fails, the
text will still be selected, so the user can still manually press
Ctrl+C
to copy the code chunk.
These options accept raw HTML strings, so you can achieve an icon-only appearance using FontAwesome icons:
```{r xaringanExtra-clipboard, echo=FALSE} htmltools::tagList( xaringanExtra::use_clipboard( button_text = "<i class=\"fa fa-clipboard\"></i>", success_text = "<i class=\"fa fa-check\" style=\"color: #90BE6D\"></i>", error_text = "<i class=\"fa fa-times-circle\" style=\"color: #F94144\"></i>" ), rmarkdown::html_dependency_font_awesome() ) ```
Value
An htmltools::tagList()
with the HTML dependencies required for
clipboard.
Functions
-
use_clipboard()
: Adds clipboard to your xaringan slides or R Markdown HTML output. -
html_dependency_clipboardjs()
: Returns anhtmltools::htmlDependency()
with the clipboard.js library. For expert use. -
html_dependency_clipboard()
: Returns anhtmltools::htmlDependency()
with the clipboard dependencies for use in xaringan and R Markdown documents. Most users will want to useuse_clipboard()
instead.
References
https://clipboardjs.com/
Examples
use_clipboard()