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

Rewrite of RTF building functions and as_rtf() #638

Merged
merged 95 commits into from
Sep 29, 2020
Merged

Conversation

rich-iannone
Copy link
Member

This PR focusses on improving the RTF output of gt tables.

R/utils.R Outdated Show resolved Hide resolved
},
item = function(x, process) {
# TODO: probably needs something like process_children()
rtf_escape(xml2::xml_text(x))
Copy link
Member

Choose a reason for hiding this comment

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

What happens if you replace this with process(xml2::xml_children(x))?

Copy link
Member Author

Choose a reason for hiding this comment

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

If you do make just that change, it just affects the markdown to RTF conversion of lists, and, we get unprocessed XML tags in the RTF.

With the following gt code

dplyr::tibble(markdown = "- item 1\n- item 2\n\n") %>%
  gt() %>%
  fmt_markdown(vars(markdown))

We get this RTF markup (just showing the one row):

\row

\trowd\trrh0

\pard\plain\uc0\ql\clvertalc\clpadb50\clpadfb3\clpadr50\clpadfr3\clpadl50\clpadfl3\clpadt50\clpadft3\clbrdrb\brdrs\brdrw10\brdrcf1\clbrdrl\brdrs\brdrw10\brdrcf1\clbrdrr\brdrs\brdrw10\brdrcf1\cellx9468
\intbl {\f0 {\f0\fs20 \pard\intbl\itap1\tx220\tx720\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\li720\fi-720 \ls1\ilvl0\cf0 
{\listtext	}\u8226  <paragraph>
  <text xml:space="preserve">item 1</text>
</paragraph>\
{\listtext	}\u8226  <paragraph>
  <text xml:space="preserve">item 2</text>
</paragraph>\
}}\cell
\pard\plain

\row

R/utils.R Outdated
# assume there is only `type` values of "ordered" and "bullet" (unordered)
rtf_raw(
paste(
"\\pard\\intbl\\itap1\\tx220\\tx720\\tx1133\\tx1700\\tx2267\\tx2834\\tx3401\\tx3968\\tx4535\\tx5102\\tx5669\\tx6236\\tx6803\\li720\\fi-720",
Copy link
Member

Choose a reason for hiding this comment

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

Are you sure the tab-stops are needed? What happens if you remove them?

Copy link
Member Author

Choose a reason for hiding this comment

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

They aren't needed. I followed your advice and lowered the values for li and fi to 300 and it looks much better. New line:

"\\pard\\intbl\\itap1\\li300\\fi-300"

The removal of tab stops only removes those stops in Word for the cell. But I don't think they're really useful.

R/utils_render_rtf_redo.R Outdated Show resolved Hide resolved
R/utils_render_rtf_redo.R Outdated Show resolved Hide resolved
R/utils_render_rtf_redo.R Outdated Show resolved Hide resolved
R/utils_render_rtf_redo.R Outdated Show resolved Hide resolved
@rich-iannone rich-iannone marked this pull request as ready for review September 29, 2020 20:31
@jcheng5 jcheng5 self-requested a review September 29, 2020 20:31
@rich-iannone rich-iannone merged commit 6a791b5 into master Sep 29, 2020
@rich-iannone rich-iannone deleted the rtf-redo branch September 29, 2020 21:01
rich-iannone added a commit that referenced this pull request Oct 13, 2020
* master:
  Rewrite of RTF building functions and `as_rtf()` (#638)
  v0.2.2 Release Candidate (#629)
  Settable font options (#591)
  Add options for sig figs / inclusion of trailing dec marks (#546)
  Fix issues with defining column widths in `cols_width()` (#561)
  Add `scale_values` arg to `fmt_percent()` (#565)
  Restore row striping option in stub cells (`row.striping.include_stub = TRUE`) (#564)
  Refactor `data_color()` so that it executes faster (#576)
  Update R-CMD-check.yaml (#599)
  Release gt 0.2.1 (#588)
  Ensure that row ordering doesn't affect summary row calculations (#556)
rich-iannone added a commit that referenced this pull request Oct 25, 2020
* master: (30 commits)
  Spanner alignment correction (#662)
  PEN currency fix (#663)
  Fix for `gtsave()` when saving an image and specifying a `path` value (#592)
  Rewrite of RTF building functions and `as_rtf()` (#638)
  v0.2.2 Release Candidate (#629)
  Settable font options (#591)
  Add options for sig figs / inclusion of trailing dec marks (#546)
  Fix issues with defining column widths in `cols_width()` (#561)
  Add `scale_values` arg to `fmt_percent()` (#565)
  Restore row striping option in stub cells (`row.striping.include_stub = TRUE`) (#564)
  Refactor `data_color()` so that it executes faster (#576)
  Update R-CMD-check.yaml (#599)
  Release gt 0.2.1 (#588)
  Ensure that row ordering doesn't affect summary row calculations (#556)
  Update failing example (#586)
  Remove test of scales behaviour
  Squelch warnings from tibble 3.0.0/3.0.1 (#557)
  Bump cache on pkgdown.yaml for GH workflow (#570)
  Update GH Actions workflow for R CMD check (#568)
  Update Description of package to be less confusing (#569)
  ...
@rich-iannone rich-iannone linked an issue Apr 27, 2021 that may be closed by this pull request
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.

Support non-ascii characters for rtf or word document
2 participants