Skip to content

Commit 782d4e2

Browse files
maellehadley
andauthored
Put parentheses inside \seealso{} links (#2922)
--- Co-authored-by: Hadley Wickham <h.wickham@gmail.com>
1 parent 34f217f commit 782d4e2

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# pkgdown (development version)
22

3+
* Links generated with `\code{\link{foo}()}` now have the `()` moved into the `<a>` in the generated output (@maelle).
34
* Plots in dark mode are now transformed with a CSS filter to improve their
45
visibility (thanks to @gadenbuie).
56
* Updated the translations vignette with instructions for building non-English sites through Github Actions.

R/tweak-page.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ tweak_page <- function(html, name, pkg = list(bs_version = 3)) {
1717

1818
tweak_anchors(html)
1919
tweak_link_md(html)
20+
tweak_link_seealso(html)
2021
tweak_link_external(html, pkg = pkg)
2122
tweak_img_src(html)
2223
tweak_strip(html, !identical(pkg$development$mode, "release"))

R/tweak-tags.R

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,21 @@ tweak_link_R6 <- function(html, cur_package) {
167167
invisible()
168168
}
169169

170+
# Fix seealso links
171+
tweak_link_seealso <- function(html) {
172+
seealso_links <- xml2::xml_find_all(html, "//code[a and text() = '()']")
173+
174+
# add () inside link
175+
seealso_text <- xml2::xml_children(seealso_links)
176+
xml2::xml_text(seealso_text) <- paste0(xml2::xml_text(seealso_text), "()")
177+
178+
# remove () outside the link
179+
text_nodes <- xml2::xml_find_all(seealso_links, "./text()[. = '()']")
180+
xml2::xml_remove(text_nodes)
181+
182+
invisible()
183+
}
184+
170185
tweak_tables <- function(html) {
171186
# Ensure all tables have class="table" apart from arguments
172187
table <- xml2::xml_find_all(html, ".//table")

tests/testthat/test-tweak-tags.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,14 @@ test_that("tweak_img_src() doesn't modify absolute links", {
262262
)
263263
})
264264

265+
test_that("trailing () moved inside links", {
266+
skip_if_no_pandoc("2.16")
267+
html <- xml2::read_html('<code><a>build_site</a>()</code>')
268+
tweak_link_seealso(html)
269+
270+
expect_equal(xpath_contents(html, ".//code"), "<a>build_site()</a>")
271+
})
272+
265273
# stripped divs etc -------------------------------------------------------
266274

267275
test_that("selectively remove hide- divs", {

0 commit comments

Comments
 (0)