Skip to content

Commit d5432a4

Browse files
authored
Preserve 'rmd' code chunks in Rd (#2300)
Fixes #2298
1 parent eae9be1 commit d5432a4

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

NEWS.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# pkgdown (development version)
22

3+
* Preserve Markdown code blocks with class rmd from roxygen2 docs (@salim-b, #2298).
34
* Avoid unwanted linebreaks from parsing `DESCRIPTION` (@salim-b, #2247).
45
* Remove redundant entries in the documentation index when multiple explicit `@usage` tags are provided (@klmr, #2302)
56
* The article index now sorts vignettes and non-vignette articles alphabetically by their filename (literally, their `basename()`), by default (@jennybc, #2253).

R/tweak-reference.R

+2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ tweak_highlight_other <- function(div) {
6161
lang <- sub("sourceCode ", "", xml2::xml_attr(div, "class"))
6262
# since roxygen 7.2.0 generic code blocks have sourceCode with no lang
6363
if (!is.na(lang) && lang == "sourceCode") lang <- "r"
64+
# Pandoc does not recognize rmd as a language :-)
65+
if (tolower(lang) %in% c("rmd", "qmd")) lang <- "markdown"
6466
# many backticks to account for possible nested code blocks
6567
# like a Markdown code block with code chunks inside
6668
md <- paste0("``````", lang, "\n", xml2::xml_text(code), "\n``````")

tests/testthat/test-tweak-reference.R

+8
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ test_that("can highlight other languages", {
112112
expect_equal(xpath_text(html, "//code//span[not(span)]")[[1]], "field")
113113
})
114114

115+
test_that("can highlight 'rmd'", {
116+
skip_if_no_pandoc("2.16")
117+
html <- xml2::read_xml('<div class="rmd"><pre><code>field: value</code></pre></div>')
118+
tweak_highlight_other(html)
119+
120+
expect_equal(xpath_attr(html, "//code//span[not(span)]", "class")[[1]], "an")
121+
})
122+
115123
test_that("fails cleanly", {
116124
html <- xml2::read_xml('<div><pre><code></code></pre></div>')
117125
tweak_highlight_other(html)

0 commit comments

Comments
 (0)