Skip to content

Instantly share code, notes, and snippets.

@uzluisf
Created May 8, 2023 20:40
Show Gist options
  • Save uzluisf/297519acb0d66306d4ba72811e3bf528 to your computer and use it in GitHub Desktop.
Save uzluisf/297519acb0d66306d4ba72811e3bf528 to your computer and use it in GitHub Desktop.
Collapsible Sections in Github Markdown

Collapsible Sections

You can get collapsible blocks in Github Markdown by using the <details></details> and <summary></summary> tags. For example,

<details>
<summary>Poe's Law (click to expand)</summary>
A humorous law of Internet forums, stating that "The best way to get the right answer on
the Internet is not to ask a question; it's to post the wrong answer."
</details>

renders as

Poe's Law (click to expand) A humorous law of Internet forums, stating that "The best way to get the right answer on the Internet is not to ask a question; it's to post the wrong answer."

Non-collapsed Sections

In order to have non-collapsed sections by default, use <details open>. Thus

<details open>
<summary>Poe's Law (click to close)</summary>
A humorous law of Internet forums, stating that "The best way to get the right answer on
the Internet is not to ask a question; it's to post the wrong answer."
</details>

renders as

Poe's Law (click to close) A humorous law of Internet forums, stating that "The best way to get the right answer on the Internet is not to ask a question; it's to post the wrong answer."

Rule

If you've a Markdown block, then you need an empty line after the tag. Otherwise the Markdown block won't render.

For example, the code block won't render here:

<details>
<summary>Encoding a string as UTF-8 in Raku</summary>
    say "Hello!".encode('utf-8');
    # OUTPUT: «utf8:0x<48 65 6C 6C 6F 21>␤»
</details>
Encoding a string as UTF-8 in Raku say "Hello!".encode('utf-8'); # OUTPUT: «utf8:0x<48 65 6C 6C 6F 21>␤»

but this does render:

<details>
<summary>Encoding a string as UTF-8 in Raku</summary>

    say "Hello!".encode('utf-8');
    # OUTPUT: «utf8:0x<48 65 6C 6C 6F 21>␤»

</details>
Encoding a string as UTF-8 in Raku
say "Hello!".encode('utf-8');
# OUTPUT: «utf8:0x<48 65 6C 6C 6F 21>␤»
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment