Skip to content

Commit

Permalink
Hyperlink paths
Browse files Browse the repository at this point in the history
Fixes #1354
  • Loading branch information
hadley committed Jul 10, 2022
1 parent a2dce9a commit 4c94881
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# roxygen2 (development version)

* If you have a daily build of RStudio, the lists of changed Rd files are
now clickable so you can immediately see the rendered development
documentation (#1354).

* Automated usage no longer mangles nbsp in default arguments (#1342).

* Give useful error if `@describeIn` can't combine docs (#1366).
Expand Down
9 changes: 8 additions & 1 deletion R/rd.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,16 @@ roclet_output.roclet_rd <- function(x, results, base_path, ..., is_first = FALSE
contents <- map_chr(results, format)
paths <- file.path(man, names(results))

names <- unname(map_chr(results, ~ .$get_name()[[1]]))
if (length(names) > 0) {
hrefs <- paste0("rstudio:run:help(`", names, "`)")
} else {
hrefs <- character()
}

# Always check for roxygen2 header before overwriting NAMESPACE (#436),
# even when running for the first time
mapply(write_if_different, paths, contents, MoreArgs = list(check = TRUE))
mapply(write_if_different, paths, contents, href = hrefs)

if (!is_first) {
# Automatically delete any files in man directory that were generated
Expand Down
6 changes: 5 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ nice_name <- function(x) {
x
}

write_if_different <- function(path, contents, check = TRUE) {
write_if_different <- function(path, contents, href = NULL, check = TRUE) {
if (!file.exists(dirname(path))) {
dir.create(dirname(path), showWarnings = FALSE)
}
Expand All @@ -87,7 +87,11 @@ write_if_different <- function(path, contents, check = TRUE) {
))
FALSE
} else {
if (!is.null(href)) {
name <- cli::style_hyperlink(name, href)
}
cli::cli_inform("Writing {.path {name}}")

writeBin(charToRaw(contents), path)
TRUE
}
Expand Down

0 comments on commit 4c94881

Please sign in to comment.