Skip to content

Commit

Permalink
Handle empty input to flatten_para
Browse files Browse the repository at this point in the history
Fixes #656
  • Loading branch information
hadley committed May 22, 2018
1 parent 1075ee6 commit 3e8f197
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# pkgdown 1.0.0.9000

* Empty sections are now ignored (#656). Previously, empty sections caused
error `Error in rep(TRUE, length(x) - 1)`.

* `\tabular{}` now longer requires a terminal `\cr` (#664, #645).

* Added a keyboard shortcut for searching. Press `shift` + `/` to move focus
Expand Down
4 changes: 2 additions & 2 deletions R/rd-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ as_data.tag_value <- function(x, ...) {
values <- x[-seq_len(idx - 1)]
}

text <- if (length(text) > 0) flatten_para(text, ...) else NULL
values <- if (length(values) > 0) parse_descriptions(values) else NULL
text <- flatten_para(text, ...)
values <- parse_descriptions(values)

list(
title = "Value",
Expand Down
8 changes: 8 additions & 0 deletions R/rd-html.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ as_html <- function(x, ...) {
# Various types of text ------------------------------------------------------

flatten_para <- function(x, ...) {
if (length(x) == 0) {
return(character())
}

# Look for "\n" TEXT blocks after a TEXT block, and not at end of file
is_nl <- purrr::map_lgl(x, is_newline, trim = TRUE)
is_text <- purrr::map_lgl(x, inherits, "TEXT")
Expand Down Expand Up @@ -333,6 +337,10 @@ parse_items <- function(rd, ...) {
}

parse_descriptions <- function(rd, ...) {
if (length(rd) == 0) {
return(character())
}

is_item <- purrr::map_lgl(rd, inherits, "tag_item")

parse_item <- function(x) {
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-as_html.R
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ test_that("code blocks autolinked to vignettes", {

# Paragraphs --------------------------------------------------------------

test_that("empty input gives empty output", {
expect_equal(flatten_para(character()), character())
})

test_that("empty lines break paragraphs", {
expect_equal(
flatten_para(rd_text("a\nb\n\nc")),
Expand Down

0 comments on commit 3e8f197

Please sign in to comment.