Skip to content

Fix encoding issue with docx + sub_small_vals() / sub_large_vals() - #2014

Merged
rich-iannone merged 3 commits into
rstudio:masterfrom
olivroy:docx-encod-sub
Jul 11, 2025
Merged

rich-iannone merged 3 commits into
rstudio:masterfrom
olivroy:docx-encod-sub

Conversation

@olivroy

@olivroy olivroy commented Jul 10, 2025 •

Copy link
Copy Markdown
Collaborator

Summary

Sometimes, it seems that context = "default" is not properly handled. In the case of sub_small_vals(), it led to process_text() bypassing context == "word" condition and calling htmltools::htmlEscape() which causes the issue reported in #1997. I suppose the same problem happens for sub_large_vals(), so I fixed that as well. This is probably an issue elsewhere, but let's wait for reports before engaging in that direction. I made similar fixes for grid output last year #1788

In a .qmd doc

---
format: docx
---
```{r}
tibble::tibble(x = c(0.001, 0.01, 150), 
       y = c("<", "%", ">")) -> data

table <- data %>% 
  gt() %>% 
  sub_small_vals() %>% 
  sub_large_vals(threshold = 100)
table
```
image

Edit: I wanted to check, and it seems we are simply removing this from the output with this change:
middle output

Edit2: I decided not to be lazy after all and tested a bit more. I added another commit to use unicode instead which changes the output to this:

new output

Related GitHub Issues and PRs

Fixes #1997

Checklist

@olivroy
olivroy marked this pull request as draft July 10, 2025 19:35
@olivroy
olivroy marked this pull request as ready for review July 10, 2025 19:52
@olivroy olivroy changed the title Fix encoding issue with docx + sub_small_vals() Fix encoding issue with docx + sub_small_vals() / sub_large_vals() Jul 10, 2025
@olivroy
olivroy requested a review from rich-iannone July 10, 2025 20:00

@rich-iannone rich-iannone left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@rich-iannone

Copy link
Copy Markdown
Member

Thank you @olivroy !

@rich-iannone
rich-iannone merged commit a0d5353 into rstudio:master Jul 11, 2025
@olivroy
olivroy deleted the docx-encod-sub branch July 11, 2025 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gtsave() to DOCX encoding issue involving sub_small_vals

2 participants