71

How does github fold text blocks?

look at this issuecomment

Ben Smith
  • 19,589
  • 6
  • 65
  • 93
xiao luo
  • 777
  • 1
  • 5
  • 6

2 Answers2

92

Check if this follows dear-github issue 166, which mentions:

collapsible sections are supported:

<details>
<summary>Click to expand</summary>

whatever

</details>

See more in this example.

The key is to wrap the whole contents inside the <p>:

<details><summary>stuff with *mark* **down**</summary><p>

## _formatted_ **heading** with [a](link)

---
{{standard 3-backtick code block omitted from here due to escaping issues}}
---

Collapsible until here.
</p></details>

Gabriel Devillers reports in the comments that GitLab also have a similar collapsible section support.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 6
    If you want to wrap only a code block, you can leave out the `---`; you'll just need the fenced code block _with an empty line before and after_ inside the `

    `.

    – Raphael Jan 26 '21 at 11:20
  • This also [works](https://docs.gitlab.com/ee/user/markdown.html#collapsible-section) in GitLab. – Gabriel Devillers Jan 18 '23 at 09:06
  • 1
    @GabrielDevillers Thank you your feedback. I have included your comment in the answer for more visibility. – VonC Jan 18 '23 at 09:16
11

You can start the folded sections expanded by default as well.

<details open>

  <summary>click to collapse</summary>

  this one starts expanded because of the "open"

</details>
Jacob
  • 111
  • 1
  • 2