Skip to content

Commit

Permalink
Don't prematurely drop whitespace in value blocks (#2103)
Browse files Browse the repository at this point in the history
Fixes #2029
  • Loading branch information
hadley authored Jun 1, 2022
1 parent 35cb6e4 commit d1321f9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
5 changes: 2 additions & 3 deletions R/rd-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,9 @@ as_data.tag_value <- function(x, ...) {
describe_contents <- function(x, ...) {
# Drop pure whitespace nodes between items
is_ws <- purrr::map_lgl(x, is_whitespace)
x <- x[!is_ws]

# Group continguous \items{} into a <dl>
is_item <- purrr::map_lgl(x, inherits, "tag_item")
# Group contiguous \items{}/whitespace into a <dl>
is_item <- purrr::map_lgl(x, inherits, "tag_item") | is_ws
changed <- is_item[-1] != is_item[-length(is_item)]
group <- cumsum(c(TRUE, changed))

Expand Down
16 changes: 13 additions & 3 deletions tests/testthat/test-rd-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,29 @@ test_that("items are optional", {
})


test_that("whitespace between items is ignored", {
test_that("whitespace between items doesn't affect grouping", {
expect_equal(
value2html("\\item{a}{b}\n\n\\item{c}{d}\n\n\\item{e}{f}"),
c(
"<dl>",
"<dt>a</dt>", "<dd><p>b</p></dd>",
"<dt>c</dt>", "<dd><p>d</p></dd>",
"<dt>a</dt>", "<dd><p>b</p></dd>", "", "",
"<dt>c</dt>", "<dd><p>d</p></dd>", "", "",
"<dt>e</dt>", "<dd><p>f</p></dd>",
"</dl>"
)
)
})

test_that("whitespace between text is preserved", {
expect_equal(
value2html("a\n\nb\n\nc"),
c(
"<p>a</p>", "", "",
"<p>b</p>", "", "",
"<p>c</p>"
)
)
})

test_that("can have multiple interleaved blocks", {
expect_equal(
Expand Down

0 comments on commit d1321f9

Please sign in to comment.