ropensci / tinkr

Convert (R)Markdown files to XML, edit them, write them back as (R)Markdown
https://docs.ropensci.org/tinkr
GNU General Public License v3.0
57 stars 3 forks source link

how do we protect money dollar sign from math protection #121

Open maelle opened 3 hours ago

maelle commented 3 hours ago

:wave: @zkamvar I am realizing I do not know how to fix the problem below without resorting to backticks:

lines <- "With this $340k granta,"
file <- withr::local_tempfile()
brio::write_lines(lines, file)

tinkr::yarn$new(file)$protect_math()
#> Error: Inline math delimiters are not balanced.
#> 
#> HINT: If you are writing BASIC code, make sure you wrap variable
#>       names and code in backtics like so: `INKEY$`.
#> 
#> Below are the pairs that were found:
#>                   start...end
#>                   -----...---
#> With this $340k granta,...

Created on 2024-10-10 with reprex v2.1.0

Any hint?

zkamvar commented 2 hours ago

oof that's not great and is definitely a bug.

zkamvar commented 2 hours ago

Ugh.... I realize now that all of the examples we have are balanced -_-. I'm not sure why I never noticed this before:

https://github.com/ropensci/tinkr/blob/8a57235f7072dbcb7eb22516290c58b692a9c015/inst/extdata/basic-math.md?plain=1#L7-L14

zkamvar commented 2 hours ago

I think the solution may be in here:

https://github.com/ropensci/tinkr/blob/8a57235f7072dbcb7eb22516290c58b692a9c015/R/asis-nodes.R#L143-L149

If we check that lh is zero, then we can exit early.