This function parses the R code, fetches the tokens in it
(getParseData), and attach syntax highlighting commands onto
them. With proper style definitions for these commands (such as colors or
font styles), the R code will be syntax highlighted in the LaTeX/HTML output.
The two functions hi_latex and hi_html are wrappers of
hilight for LaTeX and HTML output, respectively.
a data frame of two columns containing the markup commands
prompt
whether to add prompts to the code
fallback
whether to use the fallback method, i.e. the regular
expression based method; this method is not precise and only highlights a
few types of symbols such as comments, strings and functions;
fallback will be set to TRUE when the input code fails
to be parsed
...
arguments to be passed to hilight()
Details
For the markup data frame, the first column is put before the R
tokens, and the second column is behind; the row names of the data frame must
be the R token names; a special row is named STANDARD, which contains
the markup for the standard tokens (i.e. those that do not need to be
highlighted); if missing, the built-in data frames highr:::cmd_latex
and highr:::cmd_html will be used.
This function only binds markups onto R tokens, and the real syntax
highlighting must be done with style definitions, which is out of the scope
of this package. It was designed to be used as the syntax highlighting
infrastructure of other packages such as knitr, where the colors and
font styles are properly defined in the LaTeX preamble and HTML header.
Value
A character vector for the syntax highlighted code.