highlight {highlight} | R Documentation |
syntax highlighting based on the R parser
Description
The highlight
function performs syntax highlighting based on the
results of the parse
and the investigation
of a detective.
Usage
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,
...
)
Arguments
file |
code file to parse. This is only used if the |
output |
where to write the rendered text. If this is anything else than the
default (standard output), the |
detective |
the detective chooses the style to apply to each token, basing its
investigation on the results of the |
renderer |
highlight delegates rendering the information to the renderer. This
package includes html and latex renderers. See |
encoding |
encoding to assume for the file. the argument is directly passed
to the |
parse.output |
output from the |
styles |
result of the detective investigation. A character vector with as many elements as there are tokens in the parser output |
expr |
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
|
final.newline |
logical. Indicates if a newline character is added after all tokens. |
showPrompts |
if TRUE, the highlighted text will show standard and continue prompt |
prompt |
standard prompt |
continue |
continue prompt |
initial.spaces |
should initial spaces be displayed or skipped. |
size |
font size. only respected by the latex renderer so far. |
show_line_numbers |
logical. When TRUE, line numbers are shown in the output. |
... |
additional arguments, currently ignored. |
Value
The resulting formatted text is returned invisibly. It is also
written to the output if the output is not NULL
See Also
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.
Examples
## Not run:
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 ) )
## End(Not run)