Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ijlyttle/codefolder
Enable per-page code-folding for Bookdown and Distill
https://github.com/ijlyttle/codefolder
Last synced: 17 days ago
JSON representation
Enable per-page code-folding for Bookdown and Distill
- Host: GitHub
- URL: https://github.com/ijlyttle/codefolder
- Owner: ijlyttle
- License: other
- Created: 2019-10-31T16:31:24.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2019-11-01T03:23:36.000Z (about 5 years ago)
- Last Synced: 2024-10-12T06:46:17.143Z (about 1 month ago)
- Language: R
- Homepage:
- Size: 13.7 KB
- Stars: 16
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
- jimsghstars - ijlyttle/codefolder - Enable per-page code-folding for Bookdown and Distill (R)
README
---
output: github_document
---```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```# codefolder
[![CRAN status](https://www.r-pkg.org/badges/version/codefolder)](https://CRAN.R-project.org/package=codefolder)
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
[![Travis build status](https://travis-ci.org/ijlyttle/codefolder.svg?branch=master)](https://travis-ci.org/ijlyttle/codefolder)The goal of codefolder is to provide "aftermarket" code-folding capabilty for [bookdown](https://bookdown.org/yihui/bookdown) and [distill](https://rstudio.github.io/distill). The operative code is based on this Stack Overflow [answer](https://stackoverflow.com/a/45501553) by Sébastien Rochette.
## Installation
You can install the delevopment version of codefolder from [GitHub](https://github.com/ijlyttle/codefolder) with:
``` r
# 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 ''````{r codefolder, echo=FALSE, results='asis'}
codefolder::bookdown(init = "hide")
```
````Distill:
````
`r ''````{r codefolder, echo=FALSE, results='asis'}
codefolder::distill(init = "hide")
```````
If you like, you can create these as RStudio [code snippets](https://support.rstudio.com/hc/en-us/articles/204463668-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](CODE_OF_CONDUCT.md).
By contributing to this project, you agree to abide by its terms.