You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
nested fenced code block messes up source highlighting in the editor #10079
RStudio Edition : Desktop [Open Source]
RStudio Version : 2022.1.0.199
OS Version : Windows 10 x64 (build 19043)
R Version : R version 4.1.1 (2021-08-10)
Steps to reproduce the problem
Open a new rmarkdown document and paste the following content
---title: "Test"output: html_document---# A Header````{verbatim}We can output arbitrary content verbatim.```{r}1 + 1```The content can contain inline code like`r pi * 5^2`, too.````# Another header
Some content
Describe the problem in detail
The source editor will not correctly recognized the nested chunk and it will mess up the highlighting
Example with the code chunk not being correctly highlighted, and headers not correctly found after the chunk.
Describe the behavior you expected
This syntax is something rather new in knitr. Last version support nested chunks and some engine will benefit from this like the comment engine or the verbatim engine.
WIth the current IDE behavior, it is rather hard to write and read such content.
I would expect the highlighting of the Markdown document in the IDE to be the same as without nested chunk.
Reacted by Yihui Xie, Christophe Dervieux, Matt Crump, rkjulian, Tom Mock, Jennifer (Jenny) Bryan, Davis Vaughan, Garrick Aden-Buie, Ilia Azizi, Vilmantas Gegzna and 4 more
I believe supporting this will require a few changes.
First, the chunk highlighter would need to become stateful, and track the number of backticks used in each chunk header / footer. That implementation lives here:
The onMatch() rule would need to both track and check the number of backticks that were matched, and only switch states when the "correct" closing number of backticks is seen.
Activity
ronblum commentedon Nov 12, 2021
Reproducible with older versions of RStudio as well, going back to RStudio Desktop 1.2.5042 on MacOS 12.
kevinushey commentedon Nov 12, 2021
I believe supporting this will require a few changes.
First, the chunk highlighter would need to become stateful, and track the number of backticks used in each chunk header / footer. That implementation lives here:
https://github.com/rstudio/rstudio/blob/main/src/gwt/src/org/rstudio/studio/client/workbench/views/source/editors/text/ace/AceBackgroundHighlighter.java
Second, the Ace highlight rules would need to become stateful as well. Those rules are activated here:
rstudio/src/gwt/acesupport/acemode/rmarkdown_highlight_rules.js
Lines 58 to 66 in 686bc16
And the
embedRules()helper lives here:rstudio/src/gwt/acesupport/acemode/utils.js
Lines 98 to 143 in 686bc16
The
onMatch()rule would need to both track and check the number of backticks that were matched, and only switch states when the "correct" closing number of backticks is seen.17 remaining items
bwu62 commentedon Jun 24, 2024
Also encountering this issue myself. Commenting here to bump and to subscribe to updates. Hope someone posts a resolution soon.
kevinushey commentedon Jul 2, 2024
Moving back to triage due to amount of user interest.
rje42 commentedon Jul 3, 2024
I have encountered the same phenomenon with TikZ blocks (not even nested chunks). See the image.

Any fix would be greatly appreciated!
ronblum commentedon Jul 9, 2024
@rje42 What version of RStudio are you using?
rje42 commentedon Jul 10, 2024
@ronblum the lastest one just downloaded: Version 2024.04.2+764. It still occurs!
gtritchie commentedon Sep 18, 2024
Verified in build 2024.10.0-186 on Mac. The expected region is now highlighted.
I opened a separate issue on code folding quirks in this scenario: #15191