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 |
A function of class redoc_wrapper
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.
rmarkdown::render( redoc_example_rmd(), output_format = redoc( wrappers = list( htmlcommentwrap, latexwrap)))#> #> #>#> | | | 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 #> #>#>#> /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#> #># 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")