Skip to content

Commit

Permalink
Replace \url{} with \doi{} in package Rd when linking to DOI (#1297)
Browse files Browse the repository at this point in the history
Fixes #1296
  • Loading branch information
ThierryO authored Apr 4, 2022
1 parent 88c7ee4 commit ee7d58d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# roxygen2 (development version)

* DOIs in the `URL` field of the `DESCRIPTION` are now converted to Rd's special
`\doi{}` tag (@ThierryO, #1296).

* Curly braces in markdown links are now escaped (#1259).

* `@inherit` and friends perform less aggressive link tweaking, eliminating
Expand Down
7 changes: 6 additions & 1 deletion R/object-package.R
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
package_seealso <- function(desc) {
itemize("Useful links:", package_seealso_urls(desc))
}
package_seealso_urls <- function(desc) {
if (!is.null(desc$URL)) {
links <- paste0("\\url{", strsplit(desc$URL, ",\\s+")[[1]], "}")
links <- gsub("\\url\\{https://doi.org/", "\\doi{", links)
} else {
links <- character()
}
if (!is.null(desc$BugReports)) {
links <- c(links, paste0("Report bugs at \\url{", desc$BugReports, "}"))
}

itemize("Useful links:", links)
links
}


package_authors <- function(desc) {
authors <- tryCatch(eval(parse(text = desc$`Authors@R` %||% "")),
error = function(e) {
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/test-object-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,11 @@ test_that("person turned into meaningful text", {
person_desc(comment = c("ORCID" = "1234", "extra"))
})
})


test_that("can convert DOIs in url", {
expect_equal(
package_seealso_urls(list(URL = "https://doi.org/10.5281/zenodo.1485309")),
"\\doi{10.5281/zenodo.1485309}"
)
})

0 comments on commit ee7d58d

Please sign in to comment.