Skip to content

Commit

Permalink
Merge pull request #1229 from wurli/main
Browse files Browse the repository at this point in the history
Add support for webr code chunks in Rmd/qmd documents
  • Loading branch information
lorenzwalthert authored Sep 20, 2024
2 parents 4665f2d + dc08277 commit b477757
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
5 changes: 3 additions & 2 deletions R/transform-code.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ identify_raw_chunks <- function(lines,

if (filetype == "Rmd") {
starts <- grep(
"^[\t >]*```+\\s*\\{([Rr]( *[ ,].*)?)\\}\\s*$", lines,
perl = TRUE
"^[\t >]*```+\\s*\\{((r|webr-r|webr)( *[ ,].*)?)\\}\\s*$",
lines,
perl = TRUE, ignore.case = TRUE
)
ends <- grep("^[\t >]*```+\\s*$", lines, perl = TRUE)
ends <- purrr::imap_int(starts, ~ ends[which(ends > .x)[1L]]) %>%
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/rmd/r_and_non_r_code_chunks-in.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ Some text.
1+1
```

```{webr}
1+1
```

```{webr-r}
1+1
```

More text.

```{nonR}
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/rmd/r_and_non_r_code_chunks-out.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ Some text.
1+1
```

```{webr}
1 + 1
```

```{webr-r}
1 + 1
```

More text.

```{nonR}
Expand Down

0 comments on commit b477757

Please sign in to comment.