Skip to content

Commit

Permalink
Mimic tools:::htmlify() (#2534)
Browse files Browse the repository at this point in the history
Fixes #2530
  • Loading branch information
hadley authored May 10, 2024
1 parent a7bb4e4 commit bb2f8e3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
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)

* `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).
Expand Down
11 changes: 10 additions & 1 deletion R/rd-html.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/_snaps/rd-html.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# converts Rd unicode shortcuts

Code
rd2html("``a -- b --- c''")
Output
[1] "“a – b — c”"

# subsection generates h3

Code
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-rd-html.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ test_that("special characters are escaped", {
expect_equal(out, "a &amp; 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"), "...")
Expand Down

0 comments on commit bb2f8e3

Please sign in to comment.