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

VSCode outline fails in Rmarkdown document if there is pseudo chunk text inside the chunks #641

Open
statnmap opened this issue Nov 16, 2023 · 0 comments

Comments

@statnmap
Copy link

I know this is a specific case.
I am building functions inside a Rmarkdown document, which builds chunks.
I remarked that, as soon as there is 3 backticks in my code, the VSCode document outline is not displayed.

Here is a reprex.
With this code, there is no outline available in VSCode, near the Rmd name
image

---
title: "test vscode"
output: html_document
author: statnmap
---

```{r development, include=FALSE}
library(testthat)
```

# combine_tbl_to_file

```{r function}
#' Create R code chunk content
#' @return A character string of R code chunk content
#' @noRd
create_r_chunk <- function() {
  paste(
    "```{r}",
    "```",
    sep = "\n"
  )
}

cat(create_r_chunk())
```

As soon as I remove the paste with backticks, the outline is correct:
image

---
title: "test vscode"
output: html_document
author: statnmap
---

```{r development, include=FALSE}
library(testthat)
```

# combine_tbl_to_file

```{r function}
#' Create R code chunk content
#' @return A character string of R code chunk content
#' @noRd
create_r_chunk <- function() {
  paste(
    "",
    sep = "\n"
  )
}

cat(create_r_chunk())
```

Maybe the parsing you use to detect chunks can be a little more restrictive, and only considering chunks when there is nothing or spaces before the backticks ?

You could maybe use patterns used by {knitr}:

r$> knitr:::all_patterns$md
$chunk.begin
[1] "^[\t >]*```+\\s*\\{([a-zA-Z0-9_]+( *[ ,].*)?)\\}\\s*$"

$chunk.end
[1] "^[\t >]*```+\\s*$"

$ref.chunk
[1] "^\\s*<<(.+)>>\\s*$"

$inline.code
[1] "(?<!(^``))(?<!(\n``))`r[ #]([^`]+)\\s*`"
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

1 participant