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

protect_curly crash when quoted thing inside curlied attribute #97

Open maelle opened 1 year ago

maelle commented 1 year ago
# Works
lines <- c(
  paste0(
    '![](images/quarto-bundle.png){width="1200" fig-align="center" fig-alt="RStudio 2022.07.1+554 ',
    "Spotted Wakerobin",
    ', July 25th, 2022 New: Update Quarto to 1.0.36"}'
    )
)
temp_file <- withr::local_tempfile()
writeLines(lines, temp_file)
lala <- tinkr::yarn$new(temp_file)
lala$body
#> {xml_document}
#> <document xmlns="http://commonmark.org/xml/1.0">
#> [1] <paragraph>\n  <image destination="images/quarto-bundle.png" title=""/>\n ...
tinkr::protect_curly(lala$body)
#> {xml_document}
#> <document xmlns="http://commonmark.org/xml/1.0">
#> [1] <paragraph>\n  <image destination="images/quarto-bundle.png" title=""/>\n ...

# Does not works
lines <- c(
  paste0(
    '![](images/quarto-bundle.png){width="1200" fig-align="center" fig-alt="RStudio 2022.07.1+554 ',
    "'Spotted Wakerobin'",
    ', July 25th, 2022 New: Update Quarto to 1.0.36"}'
    )
)
temp_file <- withr::local_tempfile()
writeLines(lines, temp_file)
lala <- tinkr::yarn$new(temp_file)
lala$body
#> {xml_document}
#> <document xmlns="http://commonmark.org/xml/1.0">
#> [1] <paragraph>\n  <image destination="images/quarto-bundle.png" title=""/>\n ...
tinkr::protect_curly(lala$body)
#> Error in `purrr::map()`:
#> ℹ In index: 1.
#> Caused by error in `read_xml.raw()`:
#> ! attributes construct error [65]
#> Backtrace:
#>      ▆
#>   1. ├─tinkr::protect_curly(lala$body)
#>   2. │ └─purrr::map(curly, digest_curly, ns = ns)
#>   3. │   └─purrr:::map_("list", .x, .f, ..., .progress = .progress)
#>   4. │     ├─purrr:::with_indexed_errors(...)
#>   5. │     │ └─base::withCallingHandlers(...)
#>   6. │     ├─purrr:::call_with_cleanup(...)
#>   7. │     └─tinkr (local) .f(.x[[i]], ...)
#>   8. │       └─tinkr:::make_text_nodes(char)
#>   9. │         ├─xml2::xml_ns_strip(xml2::read_xml(doc))
#>  10. │         │ └─xml2::xml_find_all(x, "//namespace::*[name()='']/parent::*")
#>  11. │         ├─xml2::read_xml(doc)
#>  12. │         └─xml2:::read_xml.character(doc)
#>  13. │           └─xml2:::read_xml.raw(...)
#>  14. └─base::.handleSimpleError(...)
#>  15.   └─purrr (local) h(simpleError(msg, call))
#>  16.     └─cli::cli_abort(...)
#>  17.       └─rlang::abort(...)

Created on 2023-05-26 with reprex v2.0.2

zkamvar commented 1 year ago

Huh, I wonder if this is related to https://github.com/carpentries/pegboard/issues/112