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

bug with one-character inline math #101

Closed maelle closed 7 months ago

maelle commented 7 months ago

Reported by @xtimbeau via https://github.com/ropensci-review-tools/babeldown/issues/60 and related discussions

I'll try to fix it.

maelle commented 7 months ago
lines <- c("bla", "$a=1$")
temp_file <- withr::local_tempfile()
writeLines(lines, temp_file)
wool <- tinkr::yarn$new(temp_file)
tinkr::protect_math(wool$body)
#> {xml_document}
#> <document xmlns="http://commonmark.org/xml/1.0">
#> [1] <paragraph>\n  <text xml:space="preserve">bla</text>\n  <softbreak/>\n  < ...

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

vs

lines <- c("bla", "$a$")
temp_file <- withr::local_tempfile()
writeLines(lines, temp_file)
wool <- tinkr::yarn$new(temp_file)
tinkr::protect_math(wool$body)
#> Error in char[[1]]: subscript out of bounds

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