EVOLUTION-MANAGER
Edit File: hilight.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Syntax highlight an R code fragment</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for hilight {highr}"><tr><td>hilight {highr}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Syntax highlight an R code fragment</h2> <h3>Description</h3> <p>This function <code><a href="../../base/html/parse.html">parse</a></code>s the R code, fetches the tokens in it (<code><a href="../../utils/html/getParseData.html">getParseData</a></code>), 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 <code>hi_latex</code> and <code>hi_html</code> are wrappers of <code>hilight</code> for LaTeX and HTML output, respectively. </p> <h3>Usage</h3> <pre> hilight(code, format = c("latex", "html"), markup, prompt = FALSE, fallback = FALSE) hi_latex(code, ...) hi_html(code, ...) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>code</code></td> <td> <p>a character string (the R source code)</p> </td></tr> <tr valign="top"><td><code>format</code></td> <td> <p>the output format</p> </td></tr> <tr valign="top"><td><code>markup</code></td> <td> <p>a data frame of two columns containing the markup commands</p> </td></tr> <tr valign="top"><td><code>prompt</code></td> <td> <p>whether to add prompts to the code</p> </td></tr> <tr valign="top"><td><code>fallback</code></td> <td> <p>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; <code>fallback</code> will be set to <code>TRUE</code> when the input <code>code</code> fails to be <code><a href="../../base/html/parse.html">parse</a>d</code></p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>arguments to be passed to <code>hilight()</code></p> </td></tr> </table> <h3>Details</h3> <p>For the <code>markup</code> 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 <code>STANDARD</code>, 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 <code>highr:::cmd_latex</code> and <code>highr:::cmd_html</code> will be used. </p> <p>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 <span class="pkg">knitr</span>, where the colors and font styles are properly defined in the LaTeX preamble and HTML header. </p> <h3>Value</h3> <p>A character vector for the syntax highlighted code. </p> <h3>Author(s)</h3> <p>Yihui Xie <<a href="http://yihui.name">http://yihui.name</a>> and Yixuan Qiu <<a href="http://yixuan.cos.name">http://yixuan.cos.name</a>> </p> <h3>See Also</h3> <p>See the package vignettes <code>browseVignettes('highr')</code> for how this function works internally. </p> <h3>Examples</h3> <pre> library(highr) hilight("x=1 # assignment") txt = c("a <- 1 # something", "c(y=\"world\", z=\"hello\")", "b=function(x=5) {", "for(i in 1:10) { if (i < x) print(i) else break}}", "z@child # S4 slot", "'special chars <>#$%&_{}'") cat(hi_latex(txt), sep = "\n") cat(hi_html(txt), sep = "\n") # the markup data frames highr:::cmd_latex highr:::cmd_html </pre> <hr /><div style="text-align: center;">[Package <em>highr</em> version 0.8 <a href="00Index.html">Index</a>]</div> </body></html>