Skip to content

Commit

Permalink
escape characters fix
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-y committed Nov 10, 2023
1 parent da0311d commit 88e94bf
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion R/phs_report_docx.R
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,21 @@ phs_report_docx <- function(toc = FALSE,
officer::body_replace_all_text("Subtitle", stitle) %>%
officer::body_replace_all_text("DD Month YYYY", dt)

# Convert characters in output file path that need escaped for XML
xml_elt <- officer::to_wml(officer::block_pour_docx(output_file),
add_ns = TRUE)

if (grepl("&", output_file)) {
output_escape <- gsub("&", "&amp;", output_file)
xml_elt <- gsub(output_file, output_escape, xml_elt)
}

# Combine Cover and Report
cover_page %>%
officer::cursor_end() %>%
officer::body_remove() %>%
officer::body_add_break() %>%
officer::body_add_docx(output_file) %>%
officer::body_add_xml(str = xml_elt) %>%
officer::set_doc_properties(title = title) %>%
print(output_file)
}
Expand Down

0 comments on commit 88e94bf

Please sign in to comment.