Chumicat
Chumicat

Reputation: 302

Collapsable Details Block in Quarto

I want a simple Collapsable Details Block in Quarto.

In html, code are as following:

<details>
  <summary>Title</summary>
  Content Content Content Content
</details>

Expected Result

Currently, I had know that there are several ways to make a collapsable in quarto.

I had searched the documents but hadn't found the related methods.

I also asked claude, which generate a code seems make sense but actually didn't work:

::: {.details summary="Click to expand"}
This is the hidden content that will be shown when clicked.
:::

Upvotes: 1

Views: 175

Answers (1)

Quinton.Quagliano
Quinton.Quagliano

Reputation: 726

I wasn't able to find any documentation on how to create these tags with a native markdown or Quarto method. If you are just trying to avoid typing the HTML in the QMD document itself, this may be a good case to use a custom shortcode. I named by shortcode "details" with the following lua file:

details.lua

return {
    ["details"] = function(raw_args)
        summary = raw_args[1]
        content = raw_args[2]
        return pandoc.RawBlock(
            "html", 
            "<details><summary>" .. summary .. "</summary>" .. content .. "</details>")
    end,
}

Then you can call the shortcode in your QMD file in a simplified syntax

example.qmd

{{< details "Title" "Content Content Content Content" >}}

example.html

enter image description here

Upvotes: 1

Related Questions