This is mainly useful within a github README.md since github will not rendered html-styled text in colour, but will render it correctly if it is within a <svg> tags.

as_svg(
  x,
  width = 1200,
  height = 900,
  ...,
  font_size = NULL,
  style = list(),
  browsable = FALSE
)

Arguments

x

emphatic object

width, height

viewBox dimensions for SVG

...

other arguments passed to as.character.emphatic()

font_size

CSS font-size. Default: NULL means to not adjust font size. Otherwise, use valid CSS font-size specification e.g. "3em", "22px" etc.

style

html tag styling to apply to the <pre> wrapper for the returned HTML

browsable

Should the SVG be rendered to the RStudio Viewer pane when when printed (instead of console output)? Default: FALSE

Value

character string containing an SVG snippet.

Character string containing SVG representation

Details

This is just a the results of as_html() wrapped in <svg> tags

Examples

hl_diff('hello', 'there') |>
  as_svg() |>
  cat()
#> <svg fill="none" viewBox="0 0 1200 900" width="1200" height="900" xmlns="http://www.w3.org/2000/svg"><g visibility="visible">
#> <foreignObject width="100%" height="100%">
#> <div xmlns="http://www.w3.org/1999/xhtml">
#> <pre style=''>
#> <span><span>[1] &quot;</span></span><span style='color:#000000;'><span style='background-color:#9aff9a;'> </span></span><span><span>he</span></span><span style='color:#000000;'><span style='background-color:#97ffff;'>ll</span></span><span style='color:#000000;'><span style='background-color:#ff7f50;'>o</span></span><span><span>&quot;</span></span><br/><span><span>[1] &quot;</span></span><span style='color:#000000;'><span style='background-color:#9aff9a;'>t</span></span><span><span>he</span></span><span style='color:#000000;'><span style='background-color:#97ffff;'>re</span></span><span style='color:#000000;'><span style='background-color:#ff7f50;'> </span></span><span><span>&quot;</span></span>
#> </pre>
#> </div>
#> </foreignObject>
#> 
#> </g></svg>