Mixed multi-cell hide details in Pluto

I would like to hide multiple cells of details in Pluto. The example notebooks in Pluto includes the following function to hide/expand details for a single cell:

details(inputs...; summary="Show more") = @htl("""
		$(map(x -> x, inputs))

I would like to support multiple cells with potentially different types of information, such as markdown, markdown with latex and code, and code by itself. I attempted to extend the functionality but ran into two issues. First, all cells have a grey background. Second, it would not work for julia code. Is there a way to achieve this functionality? Thank you

Here is my attempt

it sounds like you want something similar to
the Div element in PlutoUI.ExperimentalLayout? except instead of outputing the div element, you want to output the detail element.


Here is a quick attempt, seems to work for me.

You can pass in additional CSS via the style keyword, you can do quite a bit with the detail/summary tags it looks like: Exploring What the Details and Summary Elements Can Do | CSS-Tricks - CSS-Tricks

# ╔═╡ 1feb4232-10d7-4fa0-ab2b-6afd0d64df8c
using HypertextLiteral

# ╔═╡ 53eb6834-67b3-4a76-a64b-9c1fec4e6cad
using PlutoUI

# ╔═╡ 0816f761-bc07-4120-b148-b6b2fe481abf
	Detail([Summary("test"), md"__foo__", @htl("<h1><marquee>bar</marquee></h1>")]); 
	Detail([Summary("test2"), md"__foo__", @htl("<h1><marquee>bar</marquee></h1>"), Dict("foo"=>Detail([Summary("nestedtest"), md"__foo__", @htl("<h1><marquee>bar</marquee></h1>")]))])

# ╔═╡ da2b5d9a-c319-4338-b7f7-05cb60ce0e07
Summary(text) = @htl("<summary>$text</summary>")

# ╔═╡ 47e65485-c485-4ee0-8998-130f3c8e179b
	Base.@kwdef struct HtlDetail
	function Base.show(io::IO, m::MIME"text/html", d::HtlDetail)
		h = @htl("""
			<details style=$(d.style) class=$(d.class)>
		show(io, m, h)

# ╔═╡ 37d2ebeb-bb23-4a52-96e4-ffcfd060d8c3
Detail(x::PlutoUI.ExperimentalLayout.Iterable; style::PlutoUI.ExperimentalLayout.CSS="", class::Union{Nothing,String}=nothing) = 
				children=[embed_display(i) for i in x], 

Thanks for looking into this. Roughly what I am trying to do is create a set of nested cells that can be hidden or revealed—almost like a mini notebook nested within a notebook. I’m not sure if it necessarily needs to have all of the same GUI functionality as a Pluto cell (i.e. the add cell button), but I was hoping to have something that supports Markdown, Julia, and Latex.

I tried modifying your example, but I couldn’t figure out how to get it to work. For example, how would you create the following 3 cells:

Cell 1

Some text

Cell 2

x = 1
y = x * 2

Cell 2

 $\theta=$ $(round.(1/3, digits=3))

Basically, what I cannot figure out how to do is include a cell/input with Julia code that shows the code and its output. This is my attempt so far.

a simple approach is:

# ╔═╡ 03c9d788-f06a-4edb-8550-f1c06a914b38
    cell1 = md"some text"

    cell2 = begin 
		x = 1
		y = x * 2

    cell3 = md"``\theta`` $(round.(1/3, digits=3))"

# ╔═╡ 9f6b0367-7df2-446e-be91-0956fb64e309
    Detail([Summary("Cell 1"), cell1]),
    Detail([Summary("Cell 2"), cell2]),
    Detail([Summary("Cell 3"), cell3])
1 Like

Thanks! It looks like I needed to wrap cell 2 in a begin block. This is close to what I need. One last question: Is there a way to display the contents of cell 2 in addition to the output?

The updated code is here.

I wanted to bump this one last time since I initially asked during the holidays when many people may not be on discourse. Basically, I want to see if anyone knows how to display Julia code and its output in a details element. Currently, it displays the output, but not the code.