Skip to content

Commit

Permalink
Keep whitespace in html tables (#777)
Browse files Browse the repository at this point in the history
Closes #775
  • Loading branch information
edelarua authored Nov 7, 2023
1 parent f834335 commit e1c121d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
5 changes: 2 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### Miscellaneous
* Applied `styler` and resolved package lint. Changed default indentation from 4 spaces to 2.
* Added Developer Guide to pkgdown site with Debugging, Split Machinery, and Tabulation sections.
* Whitespace is not trimmed when rendering tables with `as_html`.

## rtables 0.6.5
### New Features
Expand All @@ -17,9 +19,6 @@
### Miscellaneous
* Added slide decks for advanced training as internal files.

### Miscellaneous
* Added Developer Guide to pkgdown site with Debugging, Split Machinery, Table Hierarchy, and Tabulation sections.

## rtables 0.6.4
### New Features
* Added support for `.docx` exports with `export_as_docx()`.
Expand Down
1 change: 1 addition & 0 deletions R/as_html.R
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ as_html <- function(x,
rows <- apply(cells, 1, function(row) {
tags$tr(
class = class_tr,
style = "white-space:pre;",
Filter(function(x) !identical(x, NA_integer_), row)
)
})
Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/test-exporters.R
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,18 @@ test_that("as_html Viewer with newline test", {
options(oldo)
})

test_that("as_html does not trim whitespace", {
tbl <- rtable(
header = LETTERS[1:3],
format = "xx",
rrow(" r1", 1, 2, 3),
rrow(" r 2 ", 4, 3, 2, indent = 1),
rrow("r3 ", indent = 2)
)
html_tbl <- as_html(tbl)
html_parts <- html_tbl$children[[1]][[1]]$children
expect_true(all(sapply(1:4, function(x) html_parts[[x]]$attribs$style == "white-space:pre;")))
})

## https://github.com/insightsengineering/rtables/issues/308
test_that("path_enriched_df works for tables with a column that has all length 1 elements", {
Expand Down

0 comments on commit e1c121d

Please sign in to comment.