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 markupFunctionLabelType
HTML Commentshtmlcommentwrap()"htmlcomment"inline
Single-line LaTeXlatexwrap()"latex"block
Pandoc citationscitationwrap()"citation"inline
Raw Blocksrawblockwrap()"rawblock"block
Raw Spansrawspanwrap()"rawspan"inline
make_wrapper(label, regex, type = c("block", "inline"))

Arguments

label

the label to use for chunks of this type, e.g., "citation", "table". These should be unique for each type of wrapper used. redoc() will throw an error otherwise.

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 (?s) flag is recommended for multi-line expressions.

type

whether the text should be treated as inline or block text. Inlines are wrapped in span elements and blocks are wrapped in divs. These are treated differently in several ways, especially when restoring text in dedoc().

Value

A function of class redoc_wrapper

Details

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.

Examples

rmarkdown::render( redoc_example_rmd(), output_format = redoc( wrappers = list( htmlcommentwrap, latexwrap)))
#> #> #> processing file: example.preprocessed.Rmd
#> | | | 0% | |.......... | 14% #> inline R code fragments #> #> | |.................... | 29% #> label: cars #> | |.............................. | 43% #> ordinary text without R code #> #> | |........................................ | 57% #> label: unnamed-chunk-1 (with options) #> List of 1 #> $ include: logi FALSE #> #> | |.................................................. | 71% #> inline R code fragments #> #> | |............................................................ | 86% #> label: pressure (with options) #> List of 1 #> $ dev.args: language list(bg = "transparent") #>
#> | |......................................................................| 100% #> ordinary text without R code #> #>
#> output file: example.knit.md
#> /usr/bin/pandoc +RTS -K512m -RTS example.utf8.md --to docx+empty_paragraphs --from markdown+autolink_bare_uris+tex_math_single_backslash+smart+fenced_divs+bracketed_spans --output example.docx --highlight-style tango --lua-filter /home/travis/R/Library/rmarkdown/rmd/lua/pagebreak.lua --lua-filter /home/travis/R/Library/redoc/lua-filters/protect-empty.lua --eol=lf
#> #> Output created: example.docx
# 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")