Skip to content

Commit

Permalink
Merge pull request #125 from ropensci/znk/french-connection/124
Browse files Browse the repository at this point in the history
allow for French-style dollar signs
  • Loading branch information
zkamvar authored Nov 12, 2024
2 parents 2798e86 + 640e988 commit 9dc038a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
* Documents with no trailing newline will no longer throw a warning (issue: #65;
fix: #114, @zkamvar)
* Documents with dollar signs but no math will no longer fail with the
`$protect_math()` method (issue: #121, @maelle; fix: #122, @zkamvar).
`$protect_math()` method
(issue: #121, #124 @maelle; fix: #122, #125 @zkamvar)

## MISC

Expand Down
6 changes: 3 additions & 3 deletions R/asis-nodes.R
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ protect_inline_math <- function(body, ns) {
# an error.
le <- length(bmath[endless])
lh <- length(bmath[headless])
# 2024-10-10: if the number of headless tags is zero, then we are dealing
# with currency. See issue #121
if (lh == 0) {
# 2024-10-10: if the number of headless OR endless tags is zero, then we
# are dealing with currency. See issue #121 and #124
if (lh == 0 || le == 0) {
return(copy_xml(body))
}
if (le != lh) {
Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/test-asis-nodes.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ test_that("(#121) single dollar lines dont throw errors", {
expect_equal(actual, expected)
})

test_that("(#124) french dollar lines dont throw errors", {
expected <- "I've only got 2$ in the bank. Feels bad, man. Feels bad to not have 2 $\n"
math <- commonmark::markdown_xml(expected)
txt <- xml2::read_xml(math)
expect_no_error(protxt <- protect_inline_math(txt, md_ns()))
actual <- to_md(list(yaml = NULL, body = protxt))
expect_equal(actual, expected)
})

test_that("mal-formed inline math throws an informative error", {
patherr <- system.file("extdata", "basic-math.md", package = "tinkr")
me <- yarn$new(patherr, sourcepos = TRUE)
Expand Down

0 comments on commit 9dc038a

Please sign in to comment.