blob: f782a19151d218af2a76b90d3c59b03f7e426078 [file] [log] [blame]
Hao Zhuc5415632017-02-21 17:16:13 -05001# These functions are imported from knitr/highr as `:::` is not recommended by
2# CRAN
3
4#' escape special LaTeX characters
5#' @author Yihui Xie
6escape_latex <- function(x, newlines = FALSE, spaces = FALSE) {
7 x = gsub('\\\\', '\\\\textbackslash', x)
8 x = gsub('([#$%&_{}])', '\\\\\\1', x)
9 x = gsub('\\\\textbackslash', '\\\\textbackslash{}', x)
10 x = gsub('~', '\\\\textasciitilde{}', x)
11 x = gsub('\\^', '\\\\textasciicircum{}', x)
12 if (newlines) x = gsub('(?<!\n)\n(?!\n)', '\\\\\\\\', x, perl = TRUE)
13 if (spaces) x = gsub(' ', '\\\\ \\\\ ', x)
14 x
15}
16
17#' escape special HTML characters
18#' @author Yihui Xie
19escape_html <- function(x) {
20 x = gsub('&', '&amp;', x)
21 x = gsub('<', '&lt;', x)
22 x = gsub('>', '&gt;', x)
23 x = gsub('"', '&quot;', x)
24 x
25}