onbrand icon indicating copy to clipboard operation
onbrand copied to clipboard

Some markdown cannot be parsed in `md_to_officer()`

Open DanChaltiel opened this issue 1 year ago • 0 comments

Hi John,

It seems that you and I have the same problem in parsing markdown into officer.

For instance, the following example, with intricated tokens, will give an unexpected, truncated result:

library(officer)
x = "**Be bold and *italic* **: "
res = onbrand::md_to_officer(x)
fpar_obj = eval(parse(text=res$pgraph_1$fpar_cmd))
read_docx() %>%
  body_add_fpar(fpar_obj) %>%
  crosstable::write_and_open()

It happens that I finally managed to correct this bug in crosstable using a very different approach. This will now work (in the dev version)): body_add_fpar(crosstable:::parse_md(fpar_obj)).

Since I'm going to inspire a lot from onbrand (subscript and superscript are quite nice to have), I thought that might help you a bit, so feel free to adapt the following code to your needs. https://github.com/DanChaltiel/crosstable/blob/main/R/officer.R#L884

DanChaltiel avatar Nov 12 '23 12:11 DanChaltiel