The highlight
function performs syntax highlighting based on the
results of the parse
and the investigation
of a detective.
highlight(
file,
output = stdout(),
detective = simple_detective,
renderer,
encoding = "unknown",
parse.output = parse(file, encoding = encoding, keep.source = TRUE),
styles = detective(parse.output),
expr = NULL,
final.newline = FALSE,
showPrompts = FALSE,
prompt = getOption("prompt"),
continue = getOption("continue"),
initial.spaces = TRUE,
size = c("normalsize", "tiny", "scriptsize", "footnotesize", "small", "large",
"Large", "LARGE", "huge", "Huge"),
show_line_numbers = FALSE,
...
)
The resulting formatted text is returned invisibly. It is also
written to the output if the output is not NULL
code file to parse. This is only used if the parse.output
is given
where to write the rendered text. If this is anything else than the
default (standard output), the sink
function
is used to redirect the standard output to the output.
the detective chooses the style to apply to each token, basing its
investigation on the results of the parse
highlight delegates rendering the information to the renderer. This
package includes html and latex renderers. See renderer_html
and renderer_latex
encoding to assume for the file. the argument is directly passed
to the parse
.
output from the parse
. If this is given, the
arguments file
and encoding
are not used
result of the detective investigation. A character vector with as many elements as there are tokens in the parser output
In case we want to render only one expression and not the full parse
tree, this argument can be used to specify which expression
to render. The default (NULL) means render all expressions. This
feature is used by the sweave driver shipped with this package. See
HighlightWeaveLatex
logical. Indicates if a newline character is added after all tokens.
if TRUE, the highlighted text will show standard and continue prompt
standard prompt
continue prompt
should initial spaces be displayed or skipped.
font size. only respected by the latex renderer so far.
logical. When TRUE, line numbers are shown in the output.
additional arguments, currently ignored.
renderer_html
and renderer_latex
are the
two implementation of renderers currently available in this package.
simple_detective
is an example detective which does a very
simple investigation.
if (FALSE) {
tf <- tempfile()
dump( "jitter", file = tf )
highlight( file = tf, detective = simple_detective,
renderer = renderer_html( document = TRUE ) )
highlight( file = tf, detective = simple_detective,
renderer = renderer_latex( document = TRUE ) )
}
Run the code above in your browser using DataCamp Workspace