Skip to content

Commit

Permalink
Work with empty markdown files (#2466)
Browse files Browse the repository at this point in the history
Fixes #2309
  • Loading branch information
hadley authored Apr 18, 2024
1 parent 4d204e1 commit 321f012
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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).
Expand Down
4 changes: 4 additions & 0 deletions R/markdown.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-markdown.R
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down

0 comments on commit 321f012

Please sign in to comment.