blob: f782a19151d218af2a76b90d3c59b03f7e426078 [file] [log] [blame]
# These functions are imported from knitr/highr as `:::` is not recommended by
# CRAN
#' escape special LaTeX characters
#' @author Yihui Xie
escape_latex <- function(x, newlines = FALSE, spaces = FALSE) {
x = gsub('\\\\', '\\\\textbackslash', x)
x = gsub('([#$%&_{}])', '\\\\\\1', x)
x = gsub('\\\\textbackslash', '\\\\textbackslash{}', x)
x = gsub('~', '\\\\textasciitilde{}', x)
x = gsub('\\^', '\\\\textasciicircum{}', x)
if (newlines) x = gsub('(?<!\n)\n(?!\n)', '\\\\\\\\', x, perl = TRUE)
if (spaces) x = gsub(' ', '\\\\ \\\\ ', x)
x
}
#' escape special HTML characters
#' @author Yihui Xie
escape_html <- function(x) {
x = gsub('&', '&amp;', x)
x = gsub('<', '&lt;', x)
x = gsub('>', '&gt;', x)
x = gsub('"', '&quot;', x)
x
}