Skip to content

Commit

Permalink
Clarify type of html in flatten_para()
Browse files Browse the repository at this point in the history
Fixes #1117
  • Loading branch information
hadley committed Aug 29, 2019
1 parent 8e9dc10 commit bdcbcda
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Expand Up @@ -22,6 +22,9 @@

## Improvements to Rd translation

* `\item{}`s in `\describe{}` containing whitespace are translated correctly
(#1117).

* `\dots` and `\ldots` are translated to `...` instead of the ellipsis,
since they're often found in code (#1114).

Expand Down
6 changes: 3 additions & 3 deletions R/rd-html.R
Expand Up @@ -28,15 +28,15 @@ flatten_para <- function(x, ...) {
after_break <- c(FALSE, before_break[-length(x)])
groups <- cumsum(before_break | after_break)

html <- purrr::map_chr(x, as_html, ...)

html <- purrr::map(x, as_html, ...)
# split at line breaks for everything except blocks
empty <- purrr::map_lgl(x, purrr::is_empty)
needs_split <- !is_block & !empty
html[needs_split] <- purrr::map(html[needs_split], split_at_linebreaks)

blocks <- html %>%
split(groups) %>%
purrr::map(unlist) %>%
purrr::map_chr(paste, collapse = "")

# There are three types of blocks:
Expand Down Expand Up @@ -329,7 +329,7 @@ as_html.tag_enumerate <- function(x, ...) {
}
#' @export
as_html.tag_describe <- function(x, ...) {
paste0("<dl class='dl-horizontal'>\n", parse_descriptions(x[-1], ...), "</dl>")
paste0("<dl class='dl-horizontal'>\n", parse_descriptions(x[-1], ...), "\n</dl>")
}

# Effectively does nothing: only used by parse_items() to split up
Expand Down
14 changes: 14 additions & 0 deletions tests/testthat/test-rd-html.R
Expand Up @@ -309,6 +309,20 @@ test_that("cr generates line break", {
expect_equal(out, "<p>a <br /> b</p>")
})

test_that("nested item with whitespace parsed correctly", {
out <- rd2html("
\\describe{
\\item{Label}{
This text is indented in a way pkgdown doesn't like.
}}")
expect_equal(out, c(
"<dl class='dl-horizontal'>",
"<dt>Label</dt><dd><p>This text is indented in a way pkgdown doesn't like.</p></dd>",
"</dl>"
))
})

# Verbatim ----------------------------------------------------------------

test_that("newlines are preserved in preformatted blocks", {
Expand Down

0 comments on commit bdcbcda

Please sign in to comment.