Skip to content

Commit cf7d093

Browse files
committed
link to Github users and issues in pkg_news()
1 parent 45727d5 commit cf7d093

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: litedown
22
Type: Package
33
Title: A Lightweight Version of R Markdown
4-
Version: 0.6.5
4+
Version: 0.6.6
55
Authors@R: c(
66
person("Yihui", "Xie", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666", URL = "https://yihui.org")),
77
person("Tim", "Taylor", role = "ctb", comment = c(ORCID = "0000-0002-8587-7113")),

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
- `pkg_manual()` will exclude help pages with the keyword `internal` (thanks, @TimTaylor, #78).
44

5+
- `pkg_news()` will add links to Github users and issue numbers if the package is hosted on Github.
6+
57
- Allow `,` and `.` in superscripts and subscripts (thanks, @janlisec, #81).
68

79
- Fixed a bug that inline code expressions (`` `{lang} expr` ``) cannot be correctly located when the line has leading spaces that are not meaningful.

R/package.R

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,16 @@ pkg_news = function(
216216
for (i in 2:1) res = sub(sprintf('^(#{%d} .+)', i), paste0('#\\1', a), res)
217217
# shorten headings
218218
res = gsub('^## CHANGES IN ([^ ]+) VERSION( .+)', '## \\1\\2', res)
219+
# link Github @username and #issue
220+
if (length(u <- github_link(dirname(path)))) {
221+
r1 = '([[:alnum:]-]+)'; r2 = '([0-9]+)'
222+
res = gsub(paste0(' @', r1), ' [@\\1](https://github.com/\\1)', res)
223+
res = gsub(paste0(' #', r2), sprintf(' [#\\1](%sissues/\\1)', u), res)
224+
res = gsub(
225+
sprintf(' %s/%s#%s', r1, r1, r2),
226+
' [\\1/\\2#\\3](https://github.com/\\1/\\2/issues/\\3)', res
227+
)
228+
}
219229
}
220230
new_asis(res)
221231
}
@@ -247,11 +257,7 @@ pkg_code = function(
247257
) {
248258
if (!isTRUE(dir.exists(path))) return()
249259
a = header_class(toc, number_sections)
250-
if (isTRUE(link)) {
251-
u = read.dcf(file.path(path, 'DESCRIPTION'), 'BugReports')[1, 1]
252-
u = grep_sub('^(https://github.com/[^/]+/[^/]+/).*', '\\1blob/HEAD/%s', u)
253-
if (length(u)) link = u
254-
}
260+
if (isTRUE(link) && length(u <- github_link(path))) link = paste0(u, 'blob/HEAD/%s')
255261
ds = c('R', 'src')
256262
ds = ds[ds %in% list.dirs(path, FALSE, FALSE)]
257263
flat = length(ds) == 1 # if only one dir exists, list files in a flat structure
@@ -270,6 +276,12 @@ pkg_code = function(
270276
new_asis(unlist(code))
271277
}
272278

279+
# retrieve Github repo link from DESCRIPTION
280+
github_link = function(path) {
281+
u = read.dcf(file.path(path, 'DESCRIPTION'), 'BugReports')[1, 1]
282+
grep_sub('^(https://github.com/[^/]+/[^/]+/).*', '\\1', u)
283+
}
284+
273285
#' @return `pkg_citation()` returns the package citation in both the plain-text
274286
#' and BibTeX formats.
275287
#' @rdname pkg_desc

0 commit comments

Comments
 (0)