Package?cli?version 3.6.0
ansi_html(x, escape_reserved = TRUE, csi = c("drop", "keep"))
参数【x】:输入字符向量。
参数【escape_reserved】:是否转义HTML中保留的字符(&、<和>)。
参数【csi】:如何处理非sgr ANSI序列,要么“keep”,要么“drop”它们。
字符向量的HTML。
code <- withr::with_options(
list(ansi.num_colors = 256),
code_highlight(format(ansi_html))
)
hcode <- paste(ansi_html(code), collapse = "\n")
css <- paste(format(ansi_html_style()), collapse= "\n")
page <- htmltools::tagList(
htmltools::tags$head(htmltools::tags$style(css)),
htmltools::tags$pre(htmltools::HTML(hcode))
)
if (interactive()) htmltools::html_print(page)
function (x, escape_reserved = TRUE, csi = c("drop", "keep"))
{
if (!is.character(x))
x <- as.character(x)
csi <- match.arg(csi)
x <- enc2utf8(x)
if (escape_reserved) {
x <- gsub_("&", "&", x, fixed = TRUE, useBytes = TRUE)
x <- gsub_("<", "<", x, fixed = TRUE, useBytes = TRUE)
x <- gsub_(">", ">", x, fixed = TRUE, useBytes = TRUE)
}
.Call(clic_ansi_html, x, csi == "keep")
}