tinkr icon indicating copy to clipboard operation
tinkr copied to clipboard

[Breaking Changes] attribute-based node protection

Open zkamvar opened this issue 3 months ago • 0 comments

As discussed in https://github.com/ropensci/tinkr/issues/105#issuecomment-2040238007, since I have some time on my hands, I wanted to give this a go.

This shifts that paradigm from splitting nodes that need protection to one where we would use attributes to tell us where the protection needs to be applied.

Not Ready to Merge

I'm not quite ready to merge this yet because this has ripple effects for both {babeldown} as it explicitly relies on asis and curly nodes to be separated out to avoid them entering the translation fields

  ## protect content inside curly braces and math ----
  woolish$body <- tinkr::protect_math(woolish$body)
  woolish$body <- tinkr::protect_curly(woolish$body)
  curlies <- xml2::xml_find_all(woolish$body, "//*[@curly]")
  purrr::walk(curlies, protect_curly)
  maths <- xml2::xml_find_all(woolish$body, "//*[@asis='true']")
  purrr::walk(maths, protect_math)

and {pegboard} as the link transformation routines (from Jekyll -> pandoc) explicitly assume that the asis nodes exist

as shown in the documentation fix_links.R#L38-L48:

#' However, if a link uses liquid templating for a variable such as: 
#' `[Home]({{ page.root }}/index.html) and other text`, it will appear in XML as
#'
#' ```xml
#' ...
#' <text asis="true">[</text>
#' <text>Home</text>
#' <text asis="true">]</text>
#' <text>({{ page.root }}/index.html) and other text</text>
#' ...
#' ```

zkamvar avatar Apr 29 '24 19:04 zkamvar