diff --git a/NEWS.md b/NEWS.md index 073eeac5c..3c92a6c1f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,8 @@ # pkgdown (development version) +* Better handling for mix of citations with and without text version. Also + escapes HTML in the text version (@bastistician, #1507). + * Make links of 404's navbar absolute (#1524). * Make navbar specification more flexible: it is now possible to not include @@ -9,6 +12,7 @@ * change the placement of elements on the left and right * add text to the left and right (or even remove/replace default text) (#1502) + * pkgdown now recognizes GitLab URLs to the source repository and adds the corresponding icon to the navbar (#1493). diff --git a/R/build-home-citation.R b/R/build-home-citation.R index 3a906e78c..bf0ea1f44 100644 --- a/R/build-home-citation.R +++ b/R/build-home-citation.R @@ -45,19 +45,16 @@ data_citations <- function(pkg = ".") { cit <- read_citation(pkg$src_path) text_version <- format(cit, style = "textVersion") - if (identical(text_version, "")) { - cit <- list( - html = format(cit, style = "html"), - bibtex = format(cit, style = "bibtex") - ) - } else { - cit <- list( - html = paste0("
",text_version, "
"), - bibtex = format(cit, style = "bibtex") - ) - } + cit <- list( + html = ifelse( + text_version == "", + format(cit, style = "html"), + paste0("", escape_html(text_version), "
") + ), + bibtex = format(cit, style = "bibtex") + ) - purrr::transpose(cit) + purrr::transpose(cit) } build_citation_authors <- function(pkg = ".") { diff --git a/tests/testthat/_snaps/build-citation-authors.md b/tests/testthat/_snaps/build-citation-authors.md new file mode 100644 index 000000000..220471332 --- /dev/null +++ b/tests/testthat/_snaps/build-citation-authors.md @@ -0,0 +1,19 @@ +# multiple citations all have HTML and BibTeX formats + + [[1]] + [[1]]$html + [1] "A & B (2021): Proof of b < a > c.
" + + [[1]]$bibtex + [1] "@Misc{,\n title = {Proof of b < a > c},\n author = {{A} and {B}},\n year = {2021},\n}" + + + [[2]] + [[2]]$html + [1] "Two A (2022).\n“Title Two.” \n
" + + [[2]]$bibtex + [1] "@Misc{,\n title = {Title Two},\n author = {Author Two},\n year = {2022},\n}" + + + diff --git a/tests/testthat/assets/site-citation/multi/DESCRIPTION b/tests/testthat/assets/site-citation/multi/DESCRIPTION new file mode 100644 index 000000000..58c608624 --- /dev/null +++ b/tests/testthat/assets/site-citation/multi/DESCRIPTION @@ -0,0 +1,6 @@ +Package: testpackage +Title: A test package +Version: 1.0.0 +Author: Sebastian Meyer +Maintainer: Sebastian Meyerinst/CITATION
", lines)))
})
+
+test_that("multiple citations all have HTML and BibTeX formats", {
+ path <- test_path("assets/site-citation/multi")
+ citations <- data_citations(path)
+ expect_equal(lengths(citations), c(2, 2))
+ expect_snapshot_output(citations)
+})