diff --git a/R/markdown.R b/R/markdown.R index 0d70aa9cd..8fae5ef21 100644 --- a/R/markdown.R +++ b/R/markdown.R @@ -62,7 +62,7 @@ markdown_body <- function(pkg, path, strip_header = FALSE) { markdown_path_html <- function(pkg, path, strip_header = FALSE) { html_path <- withr::local_tempfile() convert_markdown_to_html(pkg, path, html_path) - xml <- xml2::read_html(html_path, encoding = "UTF-8") + xml <- read_html_keep_ansi(html_path) if (!inherits(xml, "xml_node")) { return(NULL) } diff --git a/R/tweak-page.R b/R/tweak-page.R index b5e1cf74c..32712c5f5 100644 --- a/R/tweak-page.R +++ b/R/tweak-page.R @@ -96,14 +96,17 @@ tweak_useless_toc <- function(html) { # Update file on disk ----------------------------------------------------- -update_html <- function(path, tweak, ...) { - - raw <- read_file(path) +read_html_keep_ansi <- function(path) { + raw <- read_file(path) # Following the xml 1.0 spec, libxml2 drops low-bit ASCII characters # so we convert to \u2029, relying on downlit to convert back in # token_escape(). raw <- gsub("\033", "\u2029", raw, fixed = TRUE) - html <- xml2::read_html(raw, encoding = "UTF-8") + xml2::read_html(raw, encoding = "UTF-8") +} + +update_html <- function(path, tweak, ...) { + html <- read_html_keep_ansi(path) tweak(html, ...) xml2::write_html(html, path, format = FALSE)