R/utils.R

Defines functions escape_html escape_latex parse_source spaces

# TODO: remove this function after knitr 1.42
spaces = function(n = 1, char = ' ') strrep(char, pmax(0, n))

# parse source and keep source
parse_source = function(lines) parse(text = lines, keep.source = TRUE)

# borrowed from knitr

# escape backslashes and {} for the alltt package
escape_latex = function(x) {
  x = gsub('\\\\', '\\\\textbackslash', x)
  x = gsub('([{}])', '\\\\\\1', x)
  gsub('\\\\textbackslash', '\\\\textbackslash{}', x)
}

# escape special HTML chars
escape_html = function(x) {
  x = gsub('&', '&', x)
  x = gsub('<', '&lt;', x)
  x = gsub('>', '&gt;', x)
  x = gsub('"', '&quot;', x)
  x
}

Try the highr package in your browser

Any scripts or data that you put into this service are public.

highr documentation built on Dec. 28, 2022, 2:33 a.m.