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
4 changes: 2 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@
* Whitespace between words in link text is now preserved as single
space (#628, @egnha).

* `%` in inline code blocks (#640) and links (#724) is now automatically
escaped.
* `%` in inline code (#640), code blocks (@nteetor, #699) and
links (#724) is now automatically escaped.

* Parsing of markdown links has been tweaked to reduce false positives
(#555). If you still get a false positive, you can now put `\\` in front
Expand Down
2 changes: 1 addition & 1 deletion R/markdown.R
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ markdown_tags <- list(

code_block = function(xml) {
## Large block of code
list("\\preformatted{", xml_contents(xml), "}")
list("\\preformatted{", gsub("%", "\\\\%", xml_text(xml)), "}")
},

html = function(xml) {
Expand Down
17 changes: 15 additions & 2 deletions tests/testthat/test-rd-markdown.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ test_that("code blocks work", {
#'
#' Description
#'
#' Details with a code block:\\preformatted{x <- 1:10 %>%
#' multiply_by(10) %>%
#' Details with a code block:\\preformatted{x <- 1:10 \\%>\\%
#' multiply_by(10) \\%>\\%
#' add(42)
#' }
#'
Expand All @@ -68,6 +68,19 @@ test_that("inline code escapes %", {
expect_equal(out$get_field("title")$values, "\\code{0.5\\%}")
})

test_that("code blocks escape %", {
out <- roc_proc_text(rd_roclet(), "
#' ```
#' 1:10 %>% mean()
#' ```
#'
#' @md
f <- function() 1
")[[1]]

expect_equal(out$get_field("title")$values, "\\preformatted{1:10 \\%>\\% mean()\n}")
})

test_that("inline code works with < and >", {
out <- roc_proc_text(rd_roclet(), "
#' `SELECT <name> FROM <table>`
Expand Down