rundel / parsermd

https://rundel.github.io/parsermd/
Other
76 stars 4 forks source link

Errors when parsing Rmd documents with special syntax #27

Open NuoWenLei opened 2 years ago

NuoWenLei commented 2 years ago

Function parsermd::parse_rmd() returns an error when parsing Rmd documents that use the `r ''` trick anywhere in the document.

I got this trick from bookdown's rmd cookbook. It's a way of showing verbatim chunks in knitted documents.

Are there any work-arounds? Or is this an intended result?

Rmd snippet:

Screen Shot 2021-08-03 at 10 48 17 PM

Knitr output:

Screen Shot 2021-08-03 at 10 50 43 PM

Error when ran with parse_rmd():

Screen Shot 2021-08-03 at 10 52 10 PM

Thank you, Nuo Wen Lei

rundel commented 2 years ago

I am aware of this parsing issue and I haven't come up with a satisfactory solution as of yet. I may be able to add a specific parsing rule just for this case but I find this specific syntax a bit hacky (but I completely understand the use case) which is why I have not specifically added it as of yet.

NuoWenLei commented 2 years ago

I see, thank you for the quick reply. I am currently just using images of the code chunks and I think that is a completely fine workaround, so at least for me this is not an urgent issue.

rundel commented 2 years ago

You can also try Hadley's method mentioned in knitr-example 65 https://github.com/yihui/knitr-examples/blob/master/065-rmd-chunk.Rmd which uses a zero-width space in the chunk header to prevent it from parsing as code.

NuoWenLei commented 2 years ago

ok thank you!

gadenbuie commented 2 years ago

As a frequent user of the `r ''` pattern I'd really appreciate a specific parsing rule for this use case.

```{r eval=TRUE}`r ''`
n = 10
rnorm(x)


That approach to adding literal code chunks, as well as putting the `` `r ''` `` at the start of the line, has been [widely advertised for a while](https://yihui.org/en/2017/11/knitr-verbatim-code-chunk/). I agree it's a hacky approach, but personally I find it preferable to using a zero-width space (difficult to write, impossible to see).
jennybc commented 1 year ago

Does the introduction of verbatim chunks (knitr 1.37) save us from this? Like, can you just say that that verbatim chunks are the preferred approach (probably in general) and especially if you want to use parsermd?

https://bookdown.org/yihui/rmarkdown-cookbook/verbatim-code-chunks.html