From 640e988a7992a04ce6c1126fb82c9948e5ca7d4f Mon Sep 17 00:00:00 2001 From: "Zhian N. Kamvar (UMass)" Date: Tue, 5 Nov 2024 08:59:44 -0800 Subject: [PATCH] allow for French-style dollar signs --- NEWS.md | 3 ++- R/asis-nodes.R | 6 +++--- tests/testthat/test-asis-nodes.R | 9 +++++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/NEWS.md b/NEWS.md index 2e9af1b..70f061f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/R/asis-nodes.R b/R/asis-nodes.R index 9944b95..57ae8f4 100644 --- a/R/asis-nodes.R +++ b/R/asis-nodes.R @@ -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) { diff --git a/tests/testthat/test-asis-nodes.R b/tests/testthat/test-asis-nodes.R index 238e1e2..2b0f894 100644 --- a/tests/testthat/test-asis-nodes.R +++ b/tests/testthat/test-asis-nodes.R @@ -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)