replace_html_codes: Un-escape HTML codes in text

View source: R/utilities.R

replace_html_codesR Documentation

Un-escape HTML codes in text

Description

Occasionally, we need to un-escape HTML codes in text. If text contains HTML codes, they are replaced with replacements, which, by default, describe replacements for "⁠&amp;⁠", "⁠&lt;⁠", and "⁠&gt;⁠" ("&", "<", and ">", respectively).

Usage

replace_html_codes(
  text,
  replacements = list(c("&amp;", "&"), c("&lt;", "<"), c("&gt;", ">"))
)

Arguments

text

a vector (or one-dimensional list) of character strings

replacements

a list of string pairs. Each pair consists of encoded string and unencoded string, in that order. Default is list(c("&amp;", "&"), c("&lt;", "<"), c("&gt;", ">"))

Details

HTML codes can arrive in text read from an Excel file by the openxlsx package due to a bug documented here.

Value

If text is a vector, a vector of un-encoded strings. If text is a list of strings, a list of un-encoded strings of same structure. If possible, an outgoing list has simplified structure, even to the point of conversion to vector.

Examples

replace_html_codes(list("a", "&amp;", "&lt;", "&gt;", "bcd"))
replace_html_codes(list(c("&amp;", "&amp;"), c("&lt;", "&lt;"), c("&gt;", "&gt;")))

MatthewHeun/Recca documentation built on Feb. 9, 2024, 6:18 p.m.