diff --git a/NEWS.md b/NEWS.md index 1c520b344..dc994b462 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # pkgdown (development version) +* `build_reference()` now automatically translates `--`, `---`, ``` `` ```, and `''` to their unicode equivalents (#2530). * Tweaked navbar display on mobile so that long titles in drop downs (e.g. article titles) are now wrapped, and the search input spans the full width (#2512). * `build_reference()` now supports `\Sexpr[results=verbatim]` (@bastistician, #2510). * `build_home()` no longer checks if the README is missing any images. This check is now performed in `build_site()`, after `build_articles()` so you can refer to images created by vignettes with warnings (#2194). diff --git a/R/rd-html.R b/R/rd-html.R index 8d0cd0e42..e55ea1416 100644 --- a/R/rd-html.R +++ b/R/rd-html.R @@ -81,7 +81,16 @@ as_html.character <- function(x, ..., escape = TRUE) { } } #' @export -as_html.TEXT <- as_html.character +as_html.TEXT <- function(x, ..., escape = TRUE) { + # tools:::htmlify + x <- gsub("---", "\u2014", x) + x <- gsub("--", "\u2013", x) + x <- gsub("``", "\u201c", x) + x <- gsub("''", "\u201d", x) + + x <- as_html.character(x, ..., escape = escape) + x +} #' @export as_html.RCODE <- as_html.character #' @export diff --git a/tests/testthat/_snaps/rd-html.md b/tests/testthat/_snaps/rd-html.md index 03ba04147..53e1f88bb 100644 --- a/tests/testthat/_snaps/rd-html.md +++ b/tests/testthat/_snaps/rd-html.md @@ -1,3 +1,10 @@ +# converts Rd unicode shortcuts + + Code + rd2html("``a -- b --- c''") + Output + [1] "ā€œa ā€“ b ā€” cā€" + # subsection generates h3 Code diff --git a/tests/testthat/test-rd-html.R b/tests/testthat/test-rd-html.R index 83fd55ff7..4aeed412f 100644 --- a/tests/testthat/test-rd-html.R +++ b/tests/testthat/test-rd-html.R @@ -3,6 +3,10 @@ test_that("special characters are escaped", { expect_equal(out, "a & b") }) +test_that("converts Rd unicode shortcuts", { + expect_snapshot(rd2html("``a -- b --- c''")) +}) + test_that("simple tags translated to known good values", { # Simple insertions expect_equal(rd2html("\\ldots"), "...")