Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Word footnote special characters #1401

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ test.rtf
docs
*.html
*.qmd
/*.docx
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

* Update to `col_hide(columns=)` and `cols_unhide(columns=)` arguments. The functions no longer return an error if no columns are selected. (#1342)

* Update word processing to htmlEscape all characters before it goes into xml_t. This means now footnotes are escaped too. (#1303)

# gt 0.9.0

## New features
Expand Down
2 changes: 1 addition & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ process_text <- function(text, context = "html") {

text <- markdown_to_xml(text)
}else{
text <- htmltools::htmlEscape(as.character(text))
text <- as.character(text)
}

return(text)
Expand Down
2 changes: 1 addition & 1 deletion R/utils_render_xml.R
Original file line number Diff line number Diff line change
Expand Up @@ -2560,7 +2560,7 @@ parse_to_xml <- function(x, ...) {
),
xml_r(
xml_rPr(),
xml_t(x)
xml_t(enc2utf8(htmltools::htmlEscape(x)))
)
)

Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/_snaps/as_word.md

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions tests/testthat/test-as_word.R
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,21 @@ test_that("word ooxml escapes special characters in gt object", {

})

test_that("word ooxml escapes special characters in gt object footer", {

# Create a one-row table for these tests
exibble_min <- exibble[1, ]

## basic table with invalid footnote
exibble_min %>%
gt() %>%
tab_footnote(footnote = "p < .05, ><&\n\r\"'") %>%
as_word() %>%
expect_snapshot()

})


test_that("tables can be added to a word doc", {

check_suggests_xml()
Expand Down