Skip to content

Commit

Permalink
Also tweak_links() of the form \link[=topic]{text} (#980)
Browse files Browse the repository at this point in the history
Fixes #979
  • Loading branch information
hadley authored Nov 21, 2019
1 parent f6b46a8 commit 6073191
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
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)

* Links of the form `\link[=topic]{text}` are now automatically converted to
`\link[pkg:topic]{text}` when inherited from other packages (#979)

* Autogenerated function usage for S3/S4 methods is no longer double-escaped
(#976).

Expand Down
15 changes: 13 additions & 2 deletions R/utils-rd.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,19 @@ tweak_links <- function(x, package) {

if (is.list(x)) {
if (!is.null(tag) && tag == "\\link") {
if (is.null(attr(x, "Rd_option")) && has_topic(x[[1]], package)) {
attr(x, "Rd_option") <- structure(package, Rd_tag = "TEXT")
opt <- attr(x, "Rd_option")
if (is.null(opt)) {
if (has_topic(x[[1]], package)) {
attr(x, "Rd_option") <- structure(package, Rd_tag = "TEXT")
}
} else {
if (is.character(opt) && length(opt) == 1 && substr(opt, 1, 1) == "=") {
topic <- substr(opt, 2, nchar(opt))

if (has_topic(topic, package)) {
attr(x, "Rd_option") <- structure(paste0(package, ":", topic), Rd_tag = "TEXT")
}
}
}
} else if (length(x) > 0) {
x[] <- map(x, tweak_links, package = package)
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-utils-rd.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ test_that("has_topic() works as you'd expect", {
test_that("can tweak links to point to new package", {
rd1 <- tweak_links(parse_rd("\\link{abbreviate}"), package = "base")
rd2 <- tweak_links(parse_rd("\\link[base]{abbreviate}"), package = "base")
rd3 <- tweak_links(parse_rd("\\link[=abbreviate]{abbr}"), package = "base")

expect_equal(rd2text(rd1), "\\link[base]{abbreviate}\n")
expect_equal(rd2text(rd2), "\\link[base]{abbreviate}\n")
expect_equal(rd2text(rd3), "\\link[base:abbreviate]{abbr}\n")
})

0 comments on commit 6073191

Please sign in to comment.