#' Replace HTML special characters with HTML entities
#'
#' The characters \code{c("&", '"', "'", "<", ">")} will be replaced with
#' \code{c("&", """, "'", "<", ">")}, respectively.
#' @param string the string with (or w/o) HTML special chars
#' @return the string with special chars replaced.
#' @author Yihui Xie <\url{http://yihui.name}>
#' @seealso \code{\link{gsub}}
#' @references This function is copied directly from
#' \href{yihui/fun}{https://github.com/yihui/fun/blob/master/R/htmlspecialchars.R}.
#' @export
#' @examples
#' htmlspecialchars("<a href = 'http://yihui.name'>Yihui</a>")
#' # <a href = 'http://yihui.name'>Yihui</a>
htmlspecialchars <- function(string) {
x = c("&", '"', "'", "<", ">")
subx = c("&", """, "'", "<", ">")
for (i in seq_along(x)) {
string = gsub(x[i], subx[i], string, fixed = TRUE)
}
string
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.