feature: make all solution chunks foldable and folded by default #68
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I used this book to give an intro into R course, and it was very useful to teach both people without any prior programming or R experience, and those that have already worked a bit in R. It enabled self-paced studying, with help among participants and by the instructor. So thanks a lot for this resource!
That said, one major feedback I got, was that it was annoying to always already see the solutions to the exercises. It apparently prevented people from sitting down and thinking the exercise through, before evaluating whether they got it right. As I might want to come back to using this book and as others will probably have a similar problem, I spent the past week looking around for a way to get all ```{solution} code chunks foldable and folded by default. And here it is:
One can wrap all the respective code chunks in
<details></details>
html
tags. To automated this across all documents, I use the suggestion for such<details>
elements from the RMarkdown cookbook, and get the respective code snippet to be appended to every document in the book by using thehtml_document
includes:
tagafter_body:
. This works, when compiling the book locally withRscript -e 'bookdown::render_book("index.rmd")'
withknitr_1.42
andbookdown_0.32
.A more thorough solution would probably change the
solution
chunk engine inbookdown
to include a configuration option for the generic code folding functionality inRMarkdown
html_document
rendering. But I couldn't figure out the respective Lua code. And this solution here works, with minimal changes.