Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vectorise textVersion of bib entries #1507

Merged
merged 6 commits into from
Feb 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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).

Expand Down
21 changes: 9 additions & 12 deletions R/build-home-citation.R
Original file line number Diff line number Diff line change
Expand Up @@ -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("<p>",text_version, "</p>"),
bibtex = format(cit, style = "bibtex")
)
}
cit <- list(
html = ifelse(
text_version == "",
format(cit, style = "html"),
paste0("<p>", escape_html(text_version), "</p>")
),
bibtex = format(cit, style = "bibtex")
)

purrr::transpose(cit)
purrr::transpose(cit)
}

build_citation_authors <- function(pkg = ".") {
Expand Down
19 changes: 19 additions & 0 deletions tests/testthat/_snaps/build-citation-authors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# multiple citations all have HTML and BibTeX formats

[[1]]
[[1]]$html
[1] "<p>A &amp; B (2021): Proof of b &lt; a &gt; c.</p>"

[[1]]$bibtex
[1] "@Misc{,\n title = {Proof of b < a > c},\n author = {{A} and {B}},\n year = {2021},\n}"


[[2]]
[[2]]$html
[1] "<p>Two A (2022).\n&ldquo;Title Two.&rdquo; \n</p>"

[[2]]$bibtex
[1] "@Misc{,\n title = {Title Two},\n author = {Author Two},\n year = {2022},\n}"



6 changes: 6 additions & 0 deletions tests/testthat/assets/site-citation/multi/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Package: testpackage
Title: A test package
Version: 1.0.0
Author: Sebastian Meyer
Maintainer: Sebastian Meyer <noreply@example.org>
Description: Test multiple citations.
3 changes: 3 additions & 0 deletions tests/testthat/assets/site-citation/multi/inst/CITATION
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bibentry("misc", title="Proof of b < a > c", author=c("A", "B"), year="2021",
textVersion="A & B (2021): Proof of b < a > c.")
bibentry("misc", title="Title Two", author="Author Two", year="2022")
7 changes: 7 additions & 0 deletions tests/testthat/test-build-citation-authors.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,10 @@ test_that("source link is added to citation page", {
lines <- read_lines(path(path, "docs", "authors.html"))
expect_true(any(grepl("<code>inst/CITATION</code></a></small>", 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)
})