make_wrapper | R Documentation |
Wrapper functions are passed to the wrapper=
argument of
redoc()
to specify what text in R Markdown files should be
captured and restored when de-rendering (in addition to code chunks, inline
code, and YAML blocks). make_wrapper()
simplifies creation of these
wrapper functions and returns a function that can be passed to redoc()
.
Wrappers included in the package, all of which are used by default, are:
Type of markup | Function | Label | Type |
HTML Comments | htmlcommentwrap() | "htmlcomment" | inline |
Single-line LaTeX | latexwrap() | "latex" | block |
Pandoc citations | citationwrap() | "citation" | inline |
Raw Blocks | rawblockwrap() | "rawblock" | block |
Raw Spans | rawspanwrap() | "rawspan" | inline |
make_wrapper(label, regex, type = c("block", "inline"))
label |
the label to use for chunks of this type, e.g., "citation", "table".
These should be unique for each type of wrapper used. |
regex |
A regular expression that identifies the text to be wrapped and
restored, including all delimiters. It will search in a single string with
line breaks. ICU regular expressions are used.
The |
type |
whether the text should be treated as inline or block text. Inlines
are wrapped in |
Some captured text can not be selected by regular expressions, in which case custom functions can be provided to parse out the relevant text. See the vignette "Developing with redoc" for more detail.
A function of class redoc_wrapper
rmarkdown::render( redoc_example_rmd(), output_format = redoc( wrappers = list( htmlcommentwrap, latexwrap))) # This is how each of these functions are defined in the redoc package htmlcommentwrap <- make_wrapper( label = "htmlcomment", regex = "(?s)<!--.*?-->", type = "inline") latexwrap <- make_wrapper( label = "latex", regex = "(?<=[\n\r])\\\\\\w+.*?(?=[\n\r])", type = "block") rawblockwrap <- make_wrapper( label = "rawblock", regex = "(?s)```\\{=\\w+\\}.*?```\\h*", type = "block") rawspanwrap <- make_wrapper( label = "rawspan", regex = "(?s)`[^`]`\\{=\\w+?\\}", type = "inline") citationwrap <- make_wrapper( label = "citation", regex = "(?:@\\w+|\\[.*?-?@\\w+.*?\\](?!\\[\\(\\{))", type = "inline")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.