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

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

Open
3 tasks done
atusy opened this issue Jul 15, 2019 · 6 comments
Open
3 tasks done
Labels
bug an unexpected problem or unintended behavior theme: folding related to rmarkdown folding feature

Comments

@atusy
Copy link
Collaborator

atusy commented Jul 15, 2019

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

var rCodeBlocks = $('pre.r, pre.python, pre.bash, pre.sql, pre.cpp, pre.stan, pre.julia');

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

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

  • I have fully read the issue guide at https://yihui.name/issue/.
  • 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.
  • 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
Copy link
Collaborator

cderv commented Jan 13, 2021

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

@cderv cderv added the bug an unexpected problem or unintended behavior label Jan 13, 2021
@cderv cderv added the theme: folding related to rmarkdown folding feature label Jan 11, 2022
@royfrancis
Copy link
Contributor

royfrancis commented Jan 27, 2023

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
Copy link
Collaborator Author

atusy commented Jan 27, 2023

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

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

This is done by #1835

@atusy
Copy link
Collaborator Author

atusy commented Jan 27, 2023

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
Copy link
Collaborator

cderv commented Jan 27, 2023

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

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

@atusy
Copy link
Collaborator Author

atusy commented Jan 29, 2023

Oops, my typo. Thanks @cderv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior theme: folding related to rmarkdown folding feature
Projects
None yet
Development

No branches or pull requests

3 participants