Skip to content

Bad highlighting of nested code chunks in R Markdown documents #1500

Closed

Description

@arnaudgallou

vscode-R incorrectly highlights nested code chunks in R Markdown documents, stopping after the first closing chunk. E.g.:

````{verbatim}

```{r}
foo <- 1
```

````

produces:

bad-chunk-highlight

I'd expect to have the outermost chunk (verbatim here) fully highlighted. Note that the quarto extension highlights nested code chunks properly. That would be great to get this work for .Rmd files too though.

My system:

  • OS: macOS 12.3.1
  • VSCode Version: 1.87.1
  • R version: 4.3.2
  • vscode-R version: 2.8.2

Activity

  1. ThomasSoeiro commented on Oct 23, 2026

    @ThomasSoeiro
    Collaborator

    @arnaudgallou can you please provide a screenshot of your expected result? (and also in RStudio for completeness)

  2. mvanhorn commented on Nov 14, 2026

    @mvanhorn
    Contributor

    The chunk scanner treated every line of three or more backticks as the end of the open chunk. It did not record the length of the opening fence, so a shorter inner fence matched the same end pattern as the outer one.

    The scanner now stores the opening fence length and closes the chunk only when a later fence is at least that long. A shorter fence stays inside the outer chunk as content.

    #1947

  3. added a commit that references this issue on Nov 14, 2026
    d7eaa67
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions