Skip to content

Commit

Permalink
Respect escapes when passing links
Browse files Browse the repository at this point in the history
Fixes #720
  • Loading branch information
hadley committed Jun 28, 2018
1 parent ddd8f71 commit 9bcefb6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@
* `%` in inline code blocks is now automatically escaped (#640).

* Parsing of markdown links has been tweaked to reduce false positives
(#555)
(#555). If you still get a false positive, you can now put `\\` in front
of the `[` to avoid it being converted to a link (#720).

# roxygen2 6.0.1

Expand Down
2 changes: 1 addition & 1 deletion R/markdown.R
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ add_linkrefs_to_md <- function(text) {
regex(
comments = TRUE,
"
(?<=[^\\]]|^) # must not be preceded by ]
(?<=[^\\]\\\\]|^) # must not be preceded by ] or \
\\[([^\\]\\[]+)\\] # match anything inside of []
(?:\\[([^\\]\\[]+)\\])? # match optional second pair of []
(?=[^\\[]|$) # must not be followed by [
Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/test-rd-markdown-links.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ test_that("can not have [ inside of link", {
)
})

test_that("can escape [ to avoid spurious links", {
expect_equal(
md_link_html("\\[test\\]"),
"<p>[test]</p>\n"
)

expect_equal(
md_link_html("\\[ [test] \\]"),
"<p>[ <a href=\"R:test\">test</a> ]</p>\n",
)
})

test_that("commonmark picks up the various link references", {
cases <- list(
c("foo [func()] bar",
Expand Down

0 comments on commit 9bcefb6

Please sign in to comment.