Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The order of curly/math protection matters #105

Open
maelle opened this issue Apr 5, 2024 · 1 comment
Open

The order of curly/math protection matters #105

maelle opened this issue Apr 5, 2024 · 1 comment
Labels
docs enhancement ✨ New feature or request

Comments

@maelle
Copy link
Member

maelle commented Apr 5, 2024

Maybe to be included in the docs?

Bad

  expected <- "example\n\n$a_{ij}$ \n"

  temp_file <- withr::local_tempfile()
  brio::write_lines(expected, temp_file)
  wool <- tinkr::yarn$new(temp_file)
  wool$body <- tinkr::protect_curly(wool$body)
  wool$body <- tinkr::protect_math(wool$body)
#> 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
#> -----...---
#>   $a_...

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

Not bad

  expected <- "example\n\n$a_{ij}$ \n"

  temp_file <- withr::local_tempfile()
  brio::write_lines(expected, temp_file)
  wool <- tinkr::yarn$new(temp_file)
  wool$body <- tinkr::protect_math(wool$body)
  wool$body <- tinkr::protect_curly(wool$body)

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

h/t @xtimbeau in ropensci-review-tools/babeldown#68

@zkamvar
Copy link
Member

zkamvar commented Apr 5, 2024

Oh no you've found a Norman door!

I knew that these switches would come back to bite me in the end 🙈

I think we have three steps that we can take to solve this (and I am more than happy to do the implementation!)

  1. Basic 😐 : add documentation specifying correct order
  2. Plus 🙂 : add warning to protect_math() if there is previous curly protection
  3. Premium 😃 : add unprotect_[thing]() functions that remove protections previously implemented so that we can preemptively unprotect_curly() during protect_math().
  4. Exclusive 😁 : re-implement protection to not fragment text nodes but instead use attributes indicating column position.

Having these as actual switches instead of irreversible steps would make the experience of transferring data much easier.

@zkamvar zkamvar added enhancement ✨ New feature or request docs labels Apr 5, 2024
zkamvar added a commit that referenced this issue Apr 29, 2024
zkamvar added a commit that referenced this issue Apr 29, 2024
@zkamvar zkamvar mentioned this issue May 9, 2024
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs enhancement ✨ New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants