Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# pkgdown (development version)

* Links generated with `\code{\link{foo}()}` now have the `()` moved into the `<a>` in the generated output (@maelle).
* Plots in dark mode are now transformed with a CSS filter to improve their
visibility (thanks to @gadenbuie).
* Updated the translations vignette with instructions for building non-English sites through Github Actions.
Expand Down
1 change: 1 addition & 0 deletions R/tweak-page.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ tweak_page <- function(html, name, pkg = list(bs_version = 3)) {

tweak_anchors(html)
tweak_link_md(html)
tweak_link_seealso(html)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's slightly better for this to live with the other link tweakers?

tweak_link_external(html, pkg = pkg)
tweak_img_src(html)
tweak_strip(html, !identical(pkg$development$mode, "release"))
Expand Down
15 changes: 15 additions & 0 deletions R/tweak-tags.R
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,21 @@ tweak_link_R6 <- function(html, cur_package) {
invisible()
}

# Fix seealso links
tweak_link_seealso <- function(html) {
seealso_links <- xml2::xml_find_all(html, "//code[a and text() = '()']")

# add () inside link
seealso_text <- xml2::xml_children(seealso_links)
xml2::xml_text(seealso_text) <- paste0(xml2::xml_text(seealso_text), "()")

# remove () outside the link
text_nodes <- xml2::xml_find_all(seealso_links, "./text()[. = '()']")
xml2::xml_remove(text_nodes)

invisible()
}

tweak_tables <- function(html) {
# Ensure all tables have class="table" apart from arguments
table <- xml2::xml_find_all(html, ".//table")
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/test-tweak-tags.R
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,14 @@ test_that("tweak_img_src() doesn't modify absolute links", {
)
})

test_that("trailing () moved inside links", {
skip_if_no_pandoc("2.16")
html <- xml2::read_html('<code><a>build_site</a>()</code>')
tweak_link_seealso(html)

expect_equal(xpath_contents(html, ".//code"), "<a>build_site()</a>")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Main thing here is to use new xpath_contents() helper which makes testing a bit nicer.

})

# stripped divs etc -------------------------------------------------------

test_that("selectively remove hide- divs", {
Expand Down