Helper function that assembles user provided HTML and CSS into a temporary text file, and by default displays it in the browser. Intended for use in examples.
Usage
in_html(x, css = character(), pre = TRUE, display = TRUE, clean = display)Arguments
- x
character vector of html encoded strings.
- css
character vector of css styles.
- pre
TRUE (default) or FALSE, whether to wrap
xin PRE tags.- display
TRUE or FALSE, whether to display the resulting page in a browser window. If TRUE, will sleep for one second before returning, and will delete the temporary file used to store the HTML.
- clean
TRUE or FALSE, if TRUE and
display == TRUE, will delete the temporary file used for the web page, otherwise will leave it.
Value
character(1L) the file location of the page, invisibly, but keep in
mind it will have been deleted if clean=TRUE.
See also
Other HTML functions:
html_esc(),
make_styles(),
to_html()
Examples
txt <- "\033[31;42mHello \033[7mWorld\033[m"
writeLines(txt)
#> Hello World
html <- to_html(txt)
if (FALSE) { # \dontrun{
in_html(html) # spawns a browser window
} # }
writeLines(readLines(in_html(html, display=FALSE)))
#> <!DOCTYPE html>
#> <html>
#> <body>
#> <pre>
#> <span style='color: #BB0000; background-color: #00BB00;'>Hello </span><span style='color: #00BB00; background-color: #BB0000;'>World</span>
#> </pre>
#> </body>
#> </html>
css <- "SPAN {text-decoration: underline;}"
writeLines(readLines(in_html(html, css=css, display=FALSE)))
#> <!DOCTYPE html>
#> <html>
#> <style>
#> SPAN {text-decoration: underline;}
#> </style>
#> <body>
#> <pre>
#> <span style='color: #BB0000; background-color: #00BB00;'>Hello </span><span style='color: #00BB00; background-color: #BB0000;'>World</span>
#> </pre>
#> </body>
#> </html>
if (FALSE) { # \dontrun{
in_html(html, css)
} # }