Wrap content with fence delimiters such as backticks (code blocks) or colons
(fenced Div). Optionally the fenced block can have attributes. The function
fenced_div() is a shorthand of fenced_block(char = ':').
Usage
fenced_block(x, attrs = NULL, fence = make_fence(x, char), char = "`")
fenced_div(...)
make_fence(x, char = "`", start = 3)Arguments
- x
A character vector of the block content.
- attrs
A vector of block attributes.
- fence
The fence string, e.g.,
:::or```. This will be generated from thecharargument by default.- char
The fence character to be used to generate the fence string by default.
- ...
Arguments to be passed to
fenced_block().- start
The number of characters to start searching
xwith. If the string of this number of characters is found, add one more character, and repeat the search.
Value
fenced_block() returns a character vector that contains both the
fences and content.
make_fence() returns a character string. If the block content
contains N fence characters (e.g., backticks), use N + 1 characters as
the fence.
Examples
# code block with class 'r' and ID 'foo'
xfun::fenced_block("1+1", c(".r", "#foo"))
#> [1] "" "``` {.r #foo}" "1+1" "```"
# fenced Div
xfun::fenced_block("This is a **Div**.", char = ":")
#> [1] "" ":::" "This is a **Div**."
#> [4] ":::"
# three backticks by default
xfun::make_fence("1+1")
#> [1] "```"
# needs five backticks for the fences because content has four
xfun::make_fence(c("````r", "1+1", "````"))
#> [1] "`````"