### Discussed in https://github.com/quarto-dev/quarto-cli/discussions/2278

<div type='discussions-op-text'>

<sup>Originally posted by **mavam** September  3, 2022</sup>
I'm outputting my qmd in GFM, which puts code and output adjacent to each other. I would like to wrap *only the code* in a `<details>` section:

I tried this:

    <details><summary>Code</summary>

    ```{r}
    data |> ggplot(..)
    ```

    </details>

But this also puts the output (in this case, a plot) into the details section. I couldn't find an option for that in the [GFM docs](https://quarto.org/docs/reference/formats/markdown/gfm.html).

My hunch is that I need to write a filter, ~but wrangling the AST in Lua is a different ballpark.~  EDIT: I managed to write a filter, but it feels pretty hacky:

```lua
function CodeBlock(code_block)
    if code_block.attributes["code-fold"] == "true" then
        local open = "<details><summary>Code </summary>\n"
        local close = "\n</details>"
        local open_block = pandoc.RawBlock("html", open)
        local close_block = pandoc.RawBlock("html", close)
        return {open_block, code_block, close_block}
    end
    return code_block
end
```

Is that the right approach?

(NB: I'm aware that HTML output does this. But I need to output to GFM where there is no collapse option.)
</div>
jjallaire
2022-09-03T23:17:41Z
mcanouil
enhancement
v1.2
closed
[FR] Extend `code-fold: true` to other formats such as `gfm`
https://github.com/quarto-dev/quarto-cli/issues/2279