yihui / knitr

A general-purpose tool for dynamic report generation in R
https://yihui.org/knitr/
2.36k stars 873 forks source link

collapse is not working since 1.46 #2346

Closed cderv closed 1 month ago

cderv commented 1 month ago

It seems we missed a breakage in 1.46 release

With knitr 1.46

> xfun::raw_string(knitr::knit(text = c("```{r, collapse=TRUE}\n1 + 1\n1:1\n```")))

``` r
1 + 1
## [1] 2
1:1
## [1] 1

With knitr 1.45
`````r
> xfun::raw_string(knitr::knit(text = c("```{r, collapse=TRUE}\n1 + 1\n1:1\n```")))

```r
1 + 1
## [1] 2
1:1
## [1] 1


This was found at reprex side
* https://github.com/tidyverse/reprex/issues/463
cderv commented 1 month ago

A quick bisect shows that 5435c52469af3781541ef0708bb9fcd7dced3d45 was the commit that broke

This is when we moved to xfun::fenced_block(). When there is only one class (the language), we now have a space and the regex does not handle it

Note that using several classes or attributes works as we create the other syntax

> xfun::raw_string(knitr::knit(text = c("```{r, collapse=TRUE, class.source='b'}\n1 + 1\n1:1\n```")))

```{.r .b}
1 + 1
## [1] 2
1:1
## [1] 1

xfun::raw_string(knitr::knit(text = c("{r, collapse=TRUE, attr.source='b=true'}\n1 + 1\n1:1\n")))

1 + 1
## [1] 2
1:1
## [1] 1