Skip to content

Commit

Permalink
Only add backticks to article/template names if needed (#2567)
Browse files Browse the repository at this point in the history
Fixes #2561
  • Loading branch information
hadley authored May 21, 2024
1 parent 39ea964 commit fd9a50c
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 10 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)

* `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).
Expand Down
2 changes: 1 addition & 1 deletion R/build-articles.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
)
))
}
Expand Down
2 changes: 1 addition & 1 deletion R/build-reference-index.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
)
))
}
Expand Down
7 changes: 1 addition & 6 deletions R/usage.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/test-build-articles.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-build-reference-index.R
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down

0 comments on commit fd9a50c

Please sign in to comment.