A helper function that creates a div with class code and then calls cli_verbatim() to output code lines. The builtin theme formats these containers specially. In particular, it adds syntax highlighting to valid R code.

cli_code(
  lines = NULL,
  ...,
  language = "R",
  .auto_close = TRUE,
  .envir = environment()
)

Arguments

lines

Chracter vector, each line will be a line of code, and newline charactes also create new lines. Note that no glue substitution is performed on the code.

...

More character vectors, they are appended to lines.

language

Programming language. This is also added as a class, in addition to code.

.auto_close

Passed to cli_div() when creating the container of the code. By default the code container is closed after emitting lines and ... via cli_verbatim(). You can keep that container open with .auto_close and/or .envir, and then calling cli_verbatim() to add (more) code. Note that the code will be formatted and syntax highlighted separately for each cli_verbatim() call.

.envir

Passed to cli_div() when creating the container of the code.

Value

The id of the container that contains the code.

Examples

cli_code(format(cli::cli_blockquote))
#> #> function (quote, citation = NULL, id = NULL, class = NULL, .envir = parent.frame()) #> { #> cli__message("blockquote", list(quote = glue_cmd(quote, .envir = .envir), #> citation = glue_cmd(citation, .envir = .envir), id = id, #> class = class)) #> } #>