Description Usage Arguments Value Note Author(s) See Also Examples
The highlight
function performs syntax highlighting based on the
results of the parser
and the investigation
of a detective.
1 2 3 4 5 6 7 8 9 | highlight(file, output = stdout(), detective = simple_detective, renderer,
encoding = "unknown", parser.output = parser(file, encoding = encoding),
styles = detective(parser.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"),
...)
|
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 |
parser.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. |
... |
additional arguments, currently ignored. |
The resulting formatted text is returned invisibly. It is also
written to the output if the output is not NULL
At the moment, the result is sent to the output by means of a
call to sink
. This is mainly due to the fact
that the writing is performed by a C function and the R API does not
allow packages to use connections in the C code.
Romain Francois <romain@r-enthusiasts.com>
renderer_html
and renderer_latex
are the
two implementation of renderers currently available in this package.
The xterm256 package defines an additional renderer
that uses xterm escape sequences.
simple_detective
is an example detective which does a very
simple investigation.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | ## 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 ) )
# verbatim renderer that upper cases function names
uppercase_formatter <- function( tokens, styles, ...){
out <- tokens
fcalls <- styles == "functioncall"
out[ fcalls ] <- casefold( out[ fcalls ], upper = TRUE )
out
}
uppercase_renderer <- renderer_verbatim(
formatter = uppercase_formatter )
# to debug the formatter, use this :
# debug( uppercase_renderer$formatter )
# because this will not work:
# debug( uppercase_formatter )
highlight( file = tf, detective = simple_detective,
renderer = uppercase_renderer )
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.