Weave.jl icon indicating copy to clipboard operation
Weave.jl copied to clipboard

Folding Code Blocks of Output HTML

Open ronbactawar opened this issue 4 years ago • 1 comments

Is it possible to implement the code blocks folding similar to what is seen in R Markdown and described here:

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

Rationale:

Realistically, documents are passed around an organization to people of different specialization. It makes the most sense to have the code initially hidden so that managers, executives or others without enough coding experience to read the document without being distracted by code detail. On the other hand, users with sufficient coding knowledge would be able to peer review/inspect the code on the fly by simply unhiding/unfolding code blocks.

https://www.youtube.com/watch?v=w_97Vr-d3yM

ronbactawar avatar Jun 04 '21 18:06 ronbactawar

I was interested in this as well. My use case is making a Julia tutorial where I want to display some exercises and hide the solutions at first.

Following the Beamer example, I came up with:

---
title: TITLE
author: AUTHOR
date: DATE
---

```julia; echo=false
struct BeginDropdown
  title::String
end
BeginDropdown() = BeginDropdown("")
Base.show(io::IO, m::MIME"text/html", b::BeginDropdown) = write(io, "<details><summary style=\"display:list-item\">$(b.title)</summary>")

struct EndDropdown
end
Base.show(io::IO, m::MIME"text/html", e::EndDropdown) = write(io, "</details>")
```

! BeginDropdown("My dropdown")
```julia; term = true
1 + 1
```
! EndDropdown()

Note the addition of style=\"display:list-item\" in the summary tag, otherwise I found that the disclosure triangle is missing (see this StackOverflow question for reference).

mtfishman avatar Jun 16 '22 21:06 mtfishman