rstudio / rmarkdown

Dynamic Documents for R
https://rmarkdown.rstudio.com
GNU General Public License v3.0
2.86k stars 969 forks source link

Folding occurs on result code blocks that have specific language classes #1603

Open atusy opened 5 years ago

atusy commented 5 years ago

Currently, application of code folding depends on whether code blocks have specific language classes (r, python, bash, sql, cpp, stan, julia)

https://github.com/rstudio/rmarkdown/blob/d4b7bf18b95371cb57e5f54aff579d70a6651396/inst/rmd/h/navigation-1.1/codefolding.js#L20

Thus, code folding is applied for result code blocks if they have the above classes. This can be an unexpected behavior for users.

---
output:
  html_document:
    code_folding: show
---

```{r, class.output='r', comment=''}
identity

![image](https://user-images.githubusercontent.com/30277794/61249779-0d7e7a80-a791-11e9-9878-d78e308aef62.png)

## xfun::session_info('rmarkdown')

R version 3.6.1 (2019-07-05) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Debian GNU/Linux 9 (stretch), RStudio 1.2.1335

Locale: LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 LC_MESSAGES=C
LC_PAPER=en_US.UTF-8 LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

Package version: base64enc_0.1.3 digest_0.6.20 evaluate_0.14 glue_1.3.1 graphics_3.6.1 grDevices_3.6.1 highr_0.8 htmltools_0.3.6 jsonlite_1.6
knitr_1.23 magrittr_1.5 markdown_1.0 methods_3.6.1 mime_0.7 Rcpp_1.0.1 rmarkdown_1.14.1 stats_3.6.1 stringi_1.4.3
stringr_1.4.0 tinytex_0.14 tools_3.6.1 utils_3.6.1 xfun_0.8 yaml_2.2.0

Pandoc version: 2.7.3



---

By filing an issue to this repo, I promise that

- [x] I have fully read the issue guide at https://yihui.name/issue/.
- [x] I have provided the necessary information about my issue.
    - If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
    - If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included `xfun::session_info('rmarkdown')`. I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version: `remotes::install_github('rstudio/rmarkdown')`.
    - If I have posted the same issue elsewhere, I have also mentioned it in this issue.
- [x] I have learned the Github Markdown syntax, and formatted my issue correctly.

I understand that my issue may be closed if I don't fulfill my promises.
cderv commented 3 years ago

This has been now generalized by the PR #1835 but it did not fix this specific issue. folding is still apply also on the output code chunk if it has the language class (or foldable) and if source and results are not collapsed.

The related issue in yihui/knitr#1730 could help solve it to target source or output only.

For now nothing differentiate source code block from output code block

royfrancis commented 1 year ago

So, it possible to fold an arbitrary piece of code block which is not assigned any language?

random code

Another option would be to assign any language to it, so that it folds, but skip syntax coloring.

sh seems to be an odd one. It is not in the list, but doesn't give an error. It renders fine with syntax coloring, but doesn't fold.

atusy commented 1 year ago

If you want to fold languages not on the list, add foldable class.

```{sh, class.source = "foldable"}
echo foo


This is done by https://github.com/rstudio/rmarkdown/pull/1835
atusy commented 1 year ago

BTW, I recommend open a new issue when the topic does not match exactly.

By doing so, you will also see an issue guide that suggests you ask questions on RStudio Community or Stack Overflow.

cderv commented 1 year ago

Thanks @atusy ! Class is foldable though, isn't it ?

Documentation is here: https://bookdown.org/yihui/rmarkdown-cookbook/fold-show.html

atusy commented 1 year ago

Oops, my typo. Thanks @cderv