line / conflr

Post R Markdown documents to Confluence
https://line.github.io/conflr/
GNU General Public License v3.0
130 stars 28 forks source link

Fix for inline maths/ list elements not getting translated #157

Open tom-from-goss opened 1 year ago

tom-from-goss commented 1 year ago

The following changes to translate.R fix some issues I've been having with inline latex in confluence:

# Include this after line 64:
  # Mark $ and $$ in plain <li> so that we can replace them safely later.
list_item_nodes <- xml2::xml_find_all(html_doc, "//li/text()")
for (node in list_item_nodes) {
    text <- xml2::xml_text(node)
    text <- mark_math(text)
    text <- mark_inline_math(text)
    xml2::xml_text(node) <- text
}

Change the regex in mark_inline_math to:

x <- stringi::stri_replace_all_regex(x, "(?<=[^\\s\\\\])\\$($|(?=[\\s:.,]))", "%1%D%O%L%L%A%R%", multiline = TRUE)