From d1321f91ecc543f06e6b76409eb95e5ff7579d6b Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Wed, 1 Jun 2022 16:41:11 -0500 Subject: [PATCH] Don't prematurely drop whitespace in value blocks (#2103) Fixes #2029 --- R/rd-data.R | 5 ++--- tests/testthat/test-rd-data.R | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/R/rd-data.R b/R/rd-data.R index d6d04562e..f4eed2bd8 100644 --- a/R/rd-data.R +++ b/R/rd-data.R @@ -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
- is_item <- purrr::map_lgl(x, inherits, "tag_item") + # Group contiguous \items{}/whitespace into a
+ 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)) diff --git a/tests/testthat/test-rd-data.R b/tests/testthat/test-rd-data.R index 5be9e957d..db629b6e3 100644 --- a/tests/testthat/test-rd-data.R +++ b/tests/testthat/test-rd-data.R @@ -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( "
", - "
a
", "

b

", - "
c
", "

d

", + "
a
", "

b

", "", "", + "
c
", "

d

", "", "", "
e
", "

f

", "
" ) ) }) +test_that("whitespace between text is preserved", { + expect_equal( + value2html("a\n\nb\n\nc"), + c( + "

a

", "", "", + "

b

", "", "", + "

c

" + ) + ) +}) test_that("can have multiple interleaved blocks", { expect_equal(