如何在Github markdown中折叠内容?

78
2个回答

99

请检查这是否符合dear-github issue 166中提到的内容:

支持可折叠部分:

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

whatever

</details>

查看此示例中的更多信息

关键在于将所有内容都包装在<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评论中提到,GitLab也支持类似的可折叠部分


6
如果你只想包裹一个代码块,可以省略 ---;你只需要在 <p> 标签内部放置有空行的围栏式代码块即可。 - Raphael
这在GitLab中也可以使用。 - Gabriel Devillers
1
@GabrielDevillers 谢谢您的反馈。我已将您的评论包含在答案中以增加可见性。 - VonC

11

您也可以默认展开折叠的部分。

<details open>

  <summary>click to collapse</summary>

  this one starts expanded because of the "open"

</details>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接