Skip to content

Enable per-page code-folding for Bookdown and Distill

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md
Notifications You must be signed in to change notification settings

ijlyttle/codefolder

Repository files navigation

codefolder

CRAN status Lifecycle: experimental Travis build status

The goal of codefolder is to provide “aftermarket” code-folding capabilty for bookdown and distill. The operative code is based on this Stack Overflow answer by Sébastien Rochette.

Installation

You can install the delevopment version of codefolder from GitHub with:

# install.packages("devtools")
devtools::install_github("ijlyttle/codefolder")

Example

This is a quick way to enable code-folding, for an entire page, on a page-by-page basis.

The idea is to put an Rmd-chunk near the top of a page. When rendered, the chunk places a button in the right margin which can be used to show or hide code.

There is a function each for Bookdown and Distill. The main argument is init, which indicates if you want, initially, to "show" or "hide" the code. The other arguments are query, the CSS selector for to match the code elements, and the style to the button.

Bookdown:

```{r codefolder, echo=FALSE, results='asis'}
codefolder::bookdown(init = "hide")
```

Distill:

<aside>
```{r codefolder, echo=FALSE, results='asis'}
codefolder::distill(init = "hide")
```
</aside>

If you like, you can create these as RStudio code snippets for markdown. I use cfb and cfd as my short-codes.

It will be up to you to add some CSS according to your tastes.

Code of Conduct

Please note that the ‘codefolder’ project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

About

Enable per-page code-folding for Bookdown and Distill

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published