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,
  output_handler = evaluate::new_output_handler()
)

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.

output_handler

Custom output handler for evaluate::evaluate.

Value

An string containing HTML.

Examples

evaluate_and_highlight,Evaluate code and syntax highlight the results,Evaluate code and syntax highlight the results — evaluate_and_highlight,Source: R/evaluate.R,evaluate_and_highlight.Rd,character(0),evaluate_and_highlight,character(0),list(title = "Description", contents = "

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

"),list(description = "This function runs code and captures the output using\nevaluate::evaluate(). It syntax highlights code with highlight(),\nand combines all results into a single HTML div."),evaluate_and_highlight( code, fig_save, classes = downlit::classes_pandoc(), env = NULL, output_handler = evaluate::new_output_handler() ),list(list(name = "code", description = "

Code to evaluate (as a string).

"), list(name = "fig_save", description = "

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

"), list(name = "classes", description = "

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

"), list(name = "env", description = "

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

"), list(name = "output_handler", description = "

Custom output handler for evaluate::evaluate.

")),TRUE,
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>" #> attr(,"dependencies") #> list()
,list(list(title = "Value", contents = "

An string containing HTML.

", slug = "value")),2021,list(name = "downlit", version = "0.2.1.9000", authors = "Hadley Wickham"),list(destination = "dev", mode = "release", version_label = "default", version_tooltip = "Released version", in_dev = FALSE),list(root = "../", title = "downlit"),list(),list(type = "default", left = "
  • \n Reference\n
  • \n
  • \n Changelog\n
  • ", right = "
  • \n \n \n \n \n
  • "),list(.present = TRUE),list(version = "1.6.1.9000"),FALSE,list(left = "

    Developed by Hadley Wickham.

    ", right = "

    Site built with pkgdown 1.6.1.9000.

    "),TRUE