This function runs code and captures the output using evaluate::evaluate(). It syntax highlights code with highlight(), and combines all results into a single HTML div.

evaluate_and_highlight(
  code,
  fig_save,
  classes = downlit::classes_pandoc(),
  env = NULL
)

Arguments

code

Code to evaluate (as a string).

fig_save

A function with arguments plot and id that is responsible for saving plot to a file (using id to disambiguate multiple plots in the same chunk). It should return a list with components path, width, and height.

classes

A mapping between token names and CSS class names. Bundled classes_pandoc() and classes_chroma() provide mappings that (roughly) match Pandoc and chroma (used by hugo) classes so you can use existing themes.

env

Environment in which to evaluate code; if not supplied, defaults to a child of the global environment.

Value

An string containing HTML.

Examples

evaluate_and_highlight("1 + 2")
#> [1] "<div class='input'><span class='fl'>1</span> <span class='op'>+</span> <span class='fl'>2</span></div><div class='output co'>#&gt; [1] 3</div>"