Skip to content

Commit 1e5e127

Browse files
committed
feat: * Add support for webr code chunks in Rmd/qmd documents
1 parent 4665f2d commit 1e5e127

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

R/transform-code.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ identify_raw_chunks <- function(lines,
100100

101101
if (filetype == "Rmd") {
102102
starts <- grep(
103-
"^[\t >]*```+\\s*\\{([Rr]( *[ ,].*)?)\\}\\s*$", lines,
104-
perl = TRUE
103+
"^[\t >]*```+\\s*\\{((r|webr-r|webr)( *[ ,].*)?)\\}\\s*$",
104+
lines, perl = TRUE, ignore.case = TRUE
105105
)
106106
ends <- grep("^[\t >]*```+\\s*$", lines, perl = TRUE)
107107
ends <- purrr::imap_int(starts, ~ ends[which(ends > .x)[1L]]) %>%

tests/testthat/rmd/r_and_non_r_code_chunks-in.Rmd

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ Some text.
1818
1+1
1919
```
2020

21+
```{webr}
22+
1+1
23+
```
24+
25+
```{webr-r}
26+
1+1
27+
```
28+
2129
More text.
2230

2331
```{nonR}

tests/testthat/rmd/r_and_non_r_code_chunks-out.Rmd

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ Some text.
1818
1+1
1919
```
2020

21+
```{webr}
22+
1 + 1
23+
```
24+
25+
```{webr-r}
26+
1 + 1
27+
```
28+
2129
More text.
2230

2331
```{nonR}

0 commit comments

Comments
 (0)