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

Pandoc-style R code fences do not get downlit syntax highlighting #289

Closed
mattwarkentin opened this issue Jan 7, 2021 · 2 comments
Closed

Comments

@mattwarkentin
Copy link
Contributor

mattwarkentin commented Jan 7, 2021

Hi,

I was playing around some more and I noticed that if you use pandoc-style code fences but mark them as R code, then they do not get the same syntax hightlighting as R Markdown R code chunks. I suppose this makes sense since downlit is only used on an R Markdown code chunk that has the "R" engine (if (downlit && options$engine == "R")), and any code contained in code fences are handed off to pandoc for syntax highlighting.

Seems like this could be a bit tricky to handle, perhaps using a regex, but not impossible. Perhaps the recommendation should just be to use proper R Markdown chunks and set eval = FALSE to get consistent highlighting for documents using downlit (@hadley thoughts?).

Just thought I would share this observation, feel free to close the issue if you think it's not worth acting on. This issue can at least serve as a reminder of why this may crop up in some cases.

In the example below, chunk 1 has default pandoc highlighting, while chunk 2 and 3 are formatted the same using downlit.

---
title: "My Website"
description: |
  Welcome to the website. I hope you enjoy it!
site: distill::distill_website
---

```r
1 + 2
```

```{r eval=FALSE}
1 + 2
```

```{r}
1 + 2
```
@jjallaire
Copy link
Member

Yes, I agree that the best way here is eval = FALSE

@cderv
Copy link
Collaborator

cderv commented Jan 8, 2021

This could maybe change in the future when support in rmarkdown is done not by a knitr hook in a way it could be used by other formats based on the html_document format. Related to rstudio/rmarkdown#1941
Still working on it as some challenges still needs to be dealt with

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants