diff --git a/NEWS.md b/NEWS.md index 310ebf2bc..82fe7be98 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # pkgdown (development version) +* `template_reference()` and `template_article()` now only add backticks to function names if needed (#2561). * Custom navbars that specify `icon` but not `aria-label` will now generate a message reminding you to provide one for to improve accessibility (#2533). * `init_site()` will no longer automatically build favicons on CI systems (e.g. GHA). This is an expensive operation that uses an external service so it should only be run locally (#2553). * `build_home_index()` now reports when rendering the home page (#2544). diff --git a/R/build-articles.R b/R/build-articles.R index 6ce95d7d3..49d30859a 100644 --- a/R/build-articles.R +++ b/R/build-articles.R @@ -453,7 +453,7 @@ default_articles_index <- function(pkg = ".") { list( title = tr_("All vignettes"), desc = NULL, - contents = paste0("`", pkg$vignettes$name, "`") + contents = auto_quote(unname(pkg$vignettes$name)) ) )) } diff --git a/R/build-reference-index.R b/R/build-reference-index.R index 67e257ba5..2a31f110a 100644 --- a/R/build-reference-index.R +++ b/R/build-reference-index.R @@ -123,7 +123,7 @@ default_reference_index <- function(pkg = ".") { print_yaml(list( list( title = tr_("All functions"), - contents = paste0('`', exported$name, '`') + contents = auto_quote(unname(exported$name)) ) )) } diff --git a/R/usage.R b/R/usage.R index 49d179f2f..991b6dad3 100644 --- a/R/usage.R +++ b/R/usage.R @@ -67,12 +67,7 @@ parse_usage <- function(x) { short_name <- function(name, type, signature) { name <- escape_html(name) - - if (!is_syntactic(name)) { - qname <- paste0("`", name, "`") - } else { - qname <- name - } + qname <- auto_quote(name) if (type == "data") { qname diff --git a/R/utils.R b/R/utils.R index cc59dcee1..3b9c0afbd 100644 --- a/R/utils.R +++ b/R/utils.R @@ -38,6 +38,10 @@ rstudio_save_all <- function() { is_syntactic <- function(x) x == make.names(x) +auto_quote <- function(x) { + ifelse(is_syntactic(x), x, paste0("`", x, "`")) +} + str_trim <- function(x) gsub("^\\s+|\\s+$", "", x) str_squish <- function(x) str_trim(gsub("\\s+", " ", x)) diff --git a/tests/testthat/test-build-articles.R b/tests/testthat/test-build-articles.R index 6d6e112d4..ade1a43d4 100644 --- a/tests/testthat/test-build-articles.R +++ b/tests/testthat/test-build-articles.R @@ -253,6 +253,15 @@ test_that("internal articles aren't included and don't trigger warning", { expect_length(index$sections[[1]]$contents, 2) }) +test_that("default template includes all articles", { + pkg <- local_pkgdown_site() + dir_create(path(pkg$src_path, "vignettes")) + file_create(path(pkg$src_path, "vignettes", "a.Rmd")) + pkg <- as_pkgdown(pkg$src_path) + + expect_equal(default_articles_index(pkg)[[1]]$contents, "a") +}) + test_that("check doesn't include getting started vignette", { pkg <- local_pkgdown_site(test_path("assets/articles-resources")) getting_started <- path(pkg$src_path, "vignettes", paste0(pkg$package, ".Rmd")) diff --git a/tests/testthat/test-build-reference-index.R b/tests/testthat/test-build-reference-index.R index 8bd73f716..f6d5c8abc 100644 --- a/tests/testthat/test-build-reference-index.R +++ b/tests/testthat/test-build-reference-index.R @@ -60,9 +60,9 @@ test_that("warns if missing topics", { expect_snapshot(data_reference_index(pkg), error = TRUE) }) -test_that("default reference includes all functions", { +test_that("default reference includes all functions, only escaping non-syntactic", { ref <- default_reference_index(test_path("assets/reference")) - expect_equal(ref[[1]]$contents, paste0("`", c(letters[1:3], "e", "?"), "`")) + expect_equal(ref[[1]]$contents, c("a", "b", "c", "e", "`?`")) }) test_that("errors well when a content entry is empty", {