diff --git a/NEWS.md b/NEWS.md index 5cdb677ef..12e4bccd5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # pkgdown (development version) +* `build_home()` no longer errors when you have an empty `.md` file (#2309). * `data_template()` gives a more informative error if you've misspecified the navbar (#2312). * The skip link now becomes visible when focussed (#2138). Thanks to @glin for the styles! * `build_reference_index()` gives more informative errors if your `contents` field is malformed (#2323). diff --git a/R/markdown.R b/R/markdown.R index 5574343fe..4e040f890 100644 --- a/R/markdown.R +++ b/R/markdown.R @@ -38,6 +38,10 @@ markdown_text_block <- function(text, ...) { markdown_body <- function(path, strip_header = FALSE) { xml <- markdown_path_html(path, strip_header = strip_header) + if (is.null(xml)) { + return(NULL) + } + # Extract body of html - as.character renders as xml which adds # significant whitespace in tags like pre transformed_path <- withr::local_tempfile() diff --git a/tests/testthat/test-markdown.R b/tests/testthat/test-markdown.R index fbae59023..cbe5be266 100644 --- a/tests/testthat/test-markdown.R +++ b/tests/testthat/test-markdown.R @@ -4,6 +4,10 @@ test_that("handles empty inputs", { expect_equal(markdown_text_block(NULL), NULL) expect_equal(markdown_text_block(""), NULL) + + path <- withr::local_tempfile() + file.create(path) + expect_equal(markdown_body(path), NULL) }) test_that("header attributes are parsed", {