Learn R Programming

highlightHTML (version 0.2.5)

highlight_html: Master highlight HTML function

Description

This function inputs a markdown or rmarkdown document and exports an HTML file. The HTML file is then processed to search for tags that inject CSS automatically into the HTML file.

Usage

highlight_html(
  input,
  output,
  tags,
  browse = TRUE,
  print = FALSE,
  render = TRUE
)

Arguments

input

File name of markdown or rmarkdown file to highlight the cells of the table or text. Alternatively, if render = FALSE, a HTML file can be specified as the input.

output

Output file name of highlighted HTML file

tags

character vector with CSS tags to be added

browse

logical, If TRUE (default) output file opens in default browser, if FALSE, file is written, but not opened in browser.

print

logical, if TRUE print output to R console, if false (default) output is filtered to other methods (see browse or output).

render

logical, if TRUE (default) will call the rmarkdown::render() function to convert Rmd or md files to html prior to injecting CSS.

Details

A function that allows the alteration of HTML using CSS. This may be helpful coming from a markdown or R markdown file to alter aspects of the page based on a specific criteria. This function handles both tables as well as normal text. The options are only limited based on your knowledge of CSS.

Examples

Run this code
# NOT RUN {
# Setting path for example html files 
# To see path where these are saved, type file or file1 in the 
# r console.
# }
# NOT RUN {
file <- system.file('examples', 'bgtable.html', package = 'highlightHTML')

# Creating CSS tags to inject into HTML document
tags <- c("#bgred {background-color: #FF0000;}", 
  "#bgblue {background-color: #0000FF;}")
  
# Command to post-process HTML file - Writes to temporary file
highlight_html(input = file, output = tempfile(fileext = ".html"),  
  tags = tags, browse = FALSE)
# }

Run the code above in your browser using DataLab