Skip to content

Instantly share code, notes, and snippets.

@joyrexus
Last active February 24, 2024 15:16
Show Gist options
  • Save joyrexus/16041f2426450e73f5df9391f7f7ae5f to your computer and use it in GitHub Desktop.
Save joyrexus/16041f2426450e73f5df9391f7f7ae5f to your computer and use it in GitHub Desktop.
collapsible markdown

collapsible markdown?

CLICK ME

yes, even hidden code blocks!

print("hello world!")

@umarcbs
Copy link

umarcbs commented Sep 21, 2020

Asteraceae:
Allium Cepa

It is also called as ONION.

Ethno-Medicinal Uses Here are the uses of Onion
Map even more text

@xihajun
Copy link

xihajun commented Sep 22, 2020

I want to say

thanks!

@mcondarelli
Copy link

I have two problems with this code:

`ini_tree.h`:

summary should render as "ini_tree.h:" but doesn't.
Inserting two newlines before summary actually forces correct rendering, but leaves arrow in preceding line.

possibly unrelated:

Long listings are shown in full, while I would prefer to have a reasonably sized scrollable pane instead.

Any hint welcome

@yannisdran
Copy link

Doesn't work with TOC. It destroys my links.. :(

@bakerray
Copy link

thanks! 👍

@davemgj84
Copy link

Nice :)

@rajiff
Copy link

rajiff commented Mar 23, 2021

Awesome Entire markdown works inside this

This is intended as a quick reference and showcase. For more complete info, see John Gruber's original spec and the Github-flavored Markdown info page.

Note that there is also a Cheatsheet specific to Markdown Here if that's what you're looking for. You can also check out more Markdown tools.

Table of Contents

Headers
Emphasis
Lists
Links
Images
Code and Syntax Highlighting
Tables
Blockquotes
Inline HTML
Horizontal Rule
Line Breaks
YouTube Videos

Headers

# H1
## H2
### H3
#### H4
##### H5
###### H6

Alternatively, for H1 and H2, an underline-ish style:

Alt-H1
======

Alt-H2
------

H1

H2

H3

H4

H5
H6

Alternatively, for H1 and H2, an underline-ish style:

Alt-H1

Alt-H2

Emphasis

Emphasis, aka italics, with *asterisks* or _underscores_.

Strong emphasis, aka bold, with **asterisks** or __underscores__.

Combined emphasis with **asterisks and _underscores_**.

Strikethrough uses two tildes. ~~Scratch this.~~

Emphasis, aka italics, with asterisks or underscores.

Strong emphasis, aka bold, with asterisks or underscores.

Combined emphasis with asterisks and underscores.

Strikethrough uses two tildes. Scratch this.

Lists

(In this example, leading and trailing spaces are shown with with dots: ⋅)

1. First ordered list item
2. Another item
⋅⋅* Unordered sub-list. 
1. Actual numbers don't matter, just that it's a number
⋅⋅1. Ordered sub-list
4. And another item.

⋅⋅⋅You can have properly indented paragraphs within list items. Notice the blank line above, and the leading spaces (at least one, but we'll use three here to also align the raw Markdown).

⋅⋅⋅To have a line break without a paragraph, you will need to use two trailing spaces.⋅⋅
⋅⋅⋅Note that this line is separate, but within the same paragraph.⋅⋅
⋅⋅⋅(This is contrary to the typical GFM line break behaviour, where trailing spaces are not required.)

* Unordered list can use asterisks
- Or minuses
+ Or pluses
  1. First ordered list item
  2. Another item
  • Unordered sub-list.
  1. Actual numbers don't matter, just that it's a number

  2. Ordered sub-list

  3. And another item.

    You can have properly indented paragraphs within list items. Notice the blank line above, and the leading spaces (at least one, but we'll use three here to also align the raw Markdown).

    To have a line break without a paragraph, you will need to use two trailing spaces.
    Note that this line is separate, but within the same paragraph.
    (This is contrary to the typical GFM line break behaviour, where trailing spaces are not required.)

  • Unordered list can use asterisks
  • Or minuses
  • Or pluses

Links

There are two ways to create links.

[I'm an inline-style link](https://www.google.com)

[I'm an inline-style link with title](https://www.google.com "Google's Homepage")

[I'm a reference-style link][Arbitrary case-insensitive reference text]

[I'm a relative reference to a repository file](../blob/master/LICENSE)

[You can use numbers for reference-style link definitions][1]

Or leave it empty and use the [link text itself].

URLs and URLs in angle brackets will automatically get turned into links. 
http://www.example.com or <http://www.example.com> and sometimes 
example.com (but not on Github, for example).

Some text to show that the reference links can follow later.

[arbitrary case-insensitive reference text]: https://www.mozilla.org
[1]: http://slashdot.org
[link text itself]: http://www.reddit.com

I'm an inline-style link

I'm an inline-style link with title

I'm a reference-style link

I'm a relative reference to a repository file

You can use numbers for reference-style link definitions

Or leave it empty and use the link text itself.

URLs and URLs in angle brackets will automatically get turned into links.
http://www.example.com or http://www.example.com and sometimes
example.com (but not on Github, for example).

Some text to show that the reference links can follow later.

Images

Here's our logo (hover to see the title text):

Inline-style: 
![alt text](https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png "Logo Title Text 1")

Reference-style: 
![alt text][logo]

[logo]: https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png "Logo Title Text 2"

Here's our logo (hover to see the title text):

Inline-style:
alt text

Reference-style:
alt text

Code and Syntax Highlighting

Code blocks are part of the Markdown spec, but syntax highlighting isn't. However, many renderers -- like Github's and Markdown Here -- support syntax highlighting. Which languages are supported and how those language names should be written will vary from renderer to renderer. Markdown Here supports highlighting for dozens of languages (and not-really-languages, like diffs and HTTP headers); to see the complete list, and how to write the language names, see the highlight.js demo page.

Inline `code` has `back-ticks around` it.

Inline code has back-ticks around it.

Blocks of code are either fenced by lines with three back-ticks ```, or are indented with four spaces. I recommend only using the fenced code blocks -- they're easier and only they support syntax highlighting.

```javascript
var s = "JavaScript syntax highlighting";
alert(s);
```
 
```python
s = "Python syntax highlighting"
print s
```
 
```
No language indicated, so no syntax highlighting. 
But let's throw in a <b>tag</b>.
```
var s = "JavaScript syntax highlighting";
alert(s);
s = "Python syntax highlighting"
print s
No language indicated, so no syntax highlighting in Markdown Here (varies on Github). 
But let's throw in a <b>tag</b>.

Tables

Tables aren't part of the core Markdown spec, but they are part of GFM and Markdown Here supports them. They are an easy way of adding tables to your email -- a task that would otherwise require copy-pasting from another application.

Colons can be used to align columns.

| Tables        | Are           | Cool  |
| ------------- |:-------------:| -----:|
| col 3 is      | right-aligned | $1600 |
| col 2 is      | centered      |   $12 |
| zebra stripes | are neat      |    $1 |

There must be at least 3 dashes separating each header cell.
The outer pipes (|) are optional, and you don't need to make the 
raw Markdown line up prettily. You can also use inline Markdown.

Markdown | Less | Pretty
--- | --- | ---
*Still* | `renders` | **nicely**
1 | 2 | 3

Colons can be used to align columns.

Tables Are Cool
col 3 is right-aligned $1600
col 2 is centered $12
zebra stripes are neat $1

There must be at least 3 dashes separating each header cell. The outer pipes (|) are optional, and you don't need to make the raw Markdown line up prettily. You can also use inline Markdown.

Markdown Less Pretty
Still renders nicely
1 2 3

Blockquotes

> Blockquotes are very handy in email to emulate reply text.
> This line is part of the same quote.

Quote break.

> This is a very long line that will still be quoted properly when it wraps. Oh boy let's keep writing to make sure this is long enough to actually wrap for everyone. Oh, you can *put* **Markdown** into a blockquote. 

Blockquotes are very handy in email to emulate reply text.
This line is part of the same quote.

Quote break.

This is a very long line that will still be quoted properly when it wraps. Oh boy let's keep writing to make sure this is long enough to actually wrap for everyone. Oh, you can put Markdown into a blockquote.

Inline HTML

You can also use raw HTML in your Markdown, and it'll mostly work pretty well.

<dl>
  <dt>Definition list</dt>
  <dd>Is something people use sometimes.</dd>

  <dt>Markdown in HTML</dt>
  <dd>Does *not* work **very** well. Use HTML <em>tags</em>.</dd>
</dl>
Definition list
Is something people use sometimes.
Markdown in HTML
Does *not* work **very** well. Use HTML tags.

Horizontal Rule

Three or more...

---

Hyphens

***

Asterisks

___

Underscores

Three or more...


Hyphens


Asterisks


Underscores

Line Breaks

My basic recommendation for learning how line breaks work is to experiment and discover -- hit <Enter> once (i.e., insert one newline), then hit it twice (i.e., insert two newlines), see what happens. You'll soon learn to get what you want. "Markdown Toggle" is your friend.

Here are some things to try out:

Here's a line for us to start with.

This line is separated from the one above by two newlines, so it will be a *separate paragraph*.

This line is also a separate paragraph, but...
This line is only separated by a single newline, so it's a separate line in the *same paragraph*.

Here's a line for us to start with.

This line is separated from the one above by two newlines, so it will be a separate paragraph.

This line is also begins a separate paragraph, but...
This line is only separated by a single newline, so it's a separate line in the same paragraph.

(Technical note: Markdown Here uses GFM line breaks, so there's no need to use MD's two-space line breaks.)

YouTube Videos

They can't be added directly but you can add an image with a link to the video like this:

<a href="http://www.youtube.com/watch?feature=player_embedded&v=YOUTUBE_VIDEO_ID_HERE
" target="_blank"><img src="http://img.youtube.com/vi/YOUTUBE_VIDEO_ID_HERE/0.jpg" 
alt="IMAGE ALT TEXT HERE" width="240" height="180" border="10" /></a>

Or, in pure Markdown, but losing the image sizing and border:

[![IMAGE ALT TEXT HERE](http://img.youtube.com/vi/YOUTUBE_VIDEO_ID_HERE/0.jpg)](http://www.youtube.com/watch?v=YOUTUBE_VIDEO_ID_HERE)

Referencing a bug by #bugID in your git commit links it to the slip. For example #1.


License: CC-BY

@Arpit8081
Copy link

Is that possible without a click event? Like text will hide automatically after a few second?

@antranapp
Copy link

CLICK ME This collapsible block is open by default

@pratikbutani
Copy link

Multiple Collapsible

CLICK ME
CLICK AGAIN
Just One More Time

Thank you for your time.

Here you can follow me.

@KochVA
Copy link

KochVA commented Apr 28, 2021

Can somebody told me, how to hide under sploier this

  • Detail 1
    • Detail 1.1
    • Detail 1.2
  • Detail 2
    • Detail 2.1
      ?

@rajiff
Copy link

rajiff commented Apr 28, 2021

Can somebody told me, how to hide under sploier this

  • Detail 1

    • Detail 1.1
    • Detail 1.2
  • Detail 2

    • Detail 2.1
      ?

You can nest it
Below is what you are looking for ?

  • Detail 1
    • Detail 1.1
    • Detail 1.2
  • Detail 2
    • Detail 2.1
    • Detail 2.2

This is how the above is made

- <details><summary>Detail 1</summary>

     - Detail 1.1
     - Detail 1.2

- <details><summary>Detail 2</summary>

     - Detail 2.1
     - Detail 2.2

</details>
</details>

@RichieRunner
Copy link

CLICK ME
This collapsible block is open by default

Can you show the markdown code for this?

@KlimDos
Copy link

KlimDos commented Jun 10, 2021

God bless you =) it is just awesome!

@bernicecpz
Copy link

This is crystal clear - awesome stuff. Thank you!

@franticn
Copy link

franticn commented Jul 14, 2021

Android Node Tree

<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>

<details>
<summary><mark><font color=darkred>Android Node Tree</font></mark>
</summary>
<p>

#```xml

 <?xml version='1.0' encoding='UTF-8' standalone='yes' ?>

#```

</p>
</details>

remove # before code block

@Dji75
Copy link

Dji75 commented Jul 20, 2021

How can I have a details view expanded as default ?

@LaurenceIO
Copy link

How can I have a details view expanded as default ?

@Dji75 in case you still need this info, it is:

<details open>

@ak2766
Copy link

ak2766 commented Oct 17, 2021

Some serious magic going on here. Really helps tame long pastes.

@Wrascon
Copy link

Wrascon commented Nov 19, 2021

And how? Where is my images?

CrystalDiskInfo ![image](https://user-images.githubusercontent.com/17739216/142601548-ce0070ec-221d-4722-9306-b8f34f5b2663.png)
CrystalDiskMark C ![image](https://user-images.githubusercontent.com/17739216/142598724-3a2354cd-a178-4866-82ba-9cf42543dfb6.png)
C:\ CDM_20211119122746 ------------------------------------------------------------------------------ CrystalDiskMark 7.0.0 x64 (C) 2007-2019 hiyohiyo Crystal Dew World: https://crystalmark.info/ ------------------------------------------------------------------------------ * MB/s = 1,000,000 bytes/s [SATA/600 = 600,000,000 bytes/s] * KB = 1000 bytes, KiB = 1024 bytes

[Read]
Sequential 1MiB (Q= 8, T= 1): 100.873 MB/s [ 96.2 IOPS] < 82613.63 us>
Sequential 1MiB (Q= 1, T= 1): 49.007 MB/s [ 46.7 IOPS] < 21282.71 us>
Random 4KiB (Q= 32, T=16): 0.640 MB/s [ 156.3 IOPS] <519876.99 us>
Random 4KiB (Q= 1, T= 1): 0.350 MB/s [ 85.4 IOPS] < 11667.33 us>

[Write]
Sequential 1MiB (Q= 8, T= 1): 94.593 MB/s [ 90.2 IOPS] < 85754.18 us>
Sequential 1MiB (Q= 1, T= 1): 95.837 MB/s [ 91.4 IOPS] < 10927.93 us>
Random 4KiB (Q= 32, T=16): 1.091 MB/s [ 266.4 IOPS] <309245.24 us>
Random 4KiB (Q= 1, T= 1): 1.040 MB/s [ 253.9 IOPS] < 3920.22 us>

Profile: Default
Test: 1 GiB (x5) [Interval: 5 sec] <DefaultAffinity=DISABLED>
Date: 2021/11/19 12:27:46
OS: Windows 7 Professional [6.1 Build 7601] (x64)

CrystalDiskMark D ![image](https://user-images.githubusercontent.com/17739216/142594941-d6e3a656-fed3-4976-8585-614d939bda4a.png)
D:\ CDM_20211119121947 ------------------------------------------------------------------------------ CrystalDiskMark 7.0.0 x64 (C) 2007-2019 hiyohiyo Crystal Dew World: https://crystalmark.info/ ------------------------------------------------------------------------------ * MB/s = 1,000,000 bytes/s [SATA/600 = 600,000,000 bytes/s] * KB = 1000 bytes, KiB = 1024 bytes

[Read]
Sequential 1MiB (Q= 8, T= 1): 78.859 MB/s [ 75.2 IOPS] <104558.06 us>
Sequential 1MiB (Q= 1, T= 1): 67.952 MB/s [ 64.8 IOPS] < 15376.81 us>
Random 4KiB (Q= 32, T=16): 0.579 MB/s [ 141.4 IOPS] <546235.94 us>
Random 4KiB (Q= 1, T= 1): 0.304 MB/s [ 74.2 IOPS] < 13403.89 us>

[Write]
Sequential 1MiB (Q= 8, T= 1): 76.762 MB/s [ 73.2 IOPS] <107149.88 us>
Sequential 1MiB (Q= 1, T= 1): 57.834 MB/s [ 55.2 IOPS] < 18034.57 us>
Random 4KiB (Q= 32, T=16): 1.084 MB/s [ 264.6 IOPS] <408687.55 us>
Random 4KiB (Q= 1, T= 1): 0.896 MB/s [ 218.8 IOPS] < 4561.90 us>

Profile: Default
Test: 1 GiB (x5) [Interval: 5 sec] <DefaultAffinity=DISABLED>
Date: 2021/11/19 12:19:47
OS: Windows 7 Professional [6.1 Build 7601] (x64)

@sl1pkn07
Copy link

sl1pkn07 commented Nov 19, 2021

You neen new line between <details> the image and </details>

https://gist.github.com/joyrexus/16041f2426450e73f5df9391f7f7ae5f#gistcomment-3041229

@sahin52
Copy link

sahin52 commented Nov 25, 2021

Without adding new line, the code block does not work as expected.

@darshan315
Copy link

darshan315 commented Dec 27, 2021

@niceguysforhelp How did you make the header collapsible above (that too in line). Mine comes below one line and not beside the arrow.

Header

<details>
<summary>
  
# Header
</summary>
<p>
</details>

@Legendary-Person
Copy link

@darshan315 It seems like we need to use CSS in-order to fix the in-Line problem.

details summary > * { display: inline; }

Some Info:-

-A couple notes on this technique. First, I recommend using inline, and not inline-block, as the line wrapping issue still occurs with inline-block when the heading text extends beyond one line.

-Second, rather than changing the display value of the nested elements, you might be tempted to replace the <summary> element’s default display: list-item value with display: flex. At least I was! However, if we do this, the arrow marker will disappear. Whoops!


╵𒄉〢・ᴍʏ sᴛᴀᴛS! 👀


Commit Stats


Unfortunately, I am new to all this, and as far as I remember you can't use CSS on Github or something like that and I don't know how to add the CSS code to make everything work fine. Do message if you get the answer.

@flakrat
Copy link

flakrat commented Jan 26, 2022

Whoop, thanks for posting this. Makes for a much more readable document when including lengthy output sections (like tracebacks, etc...)

@splaisan
Copy link

splaisan commented Feb 8, 2022

wonderful, I was looking for this for a long time.
THANKS

@jacobmoroni
Copy link

jacobmoroni commented Feb 21, 2022

I saw @antranapp's comment and figured out how to do it. here it is

<details open>

  <summary>click to collapse</summary>

  this one starts expanded because of the "open"

</details>
click to collapse

this one starts expanded because of the "open"

@akcasasent
Copy link

Is there a way to have this work with links without having to write the htlm directrly?

@darshan315
Copy link

@akcasasent

For mentioning links in Markdown, refer to this.

you can also use that in the collapsable section.

Click-Here

youtube

@iamramahibrah
Copy link

Check this out this is toggle list

@TukangM
Copy link

TukangM commented Sep 22, 2022

HHH

TESST

@oh-satyo-iswara
Copy link

hello world

@Laura-Novich-OBW
Copy link

Any advice on how to get it to work in GitHub Pages? In GitHub it looks beautiful.
on the rendered page, much less so.

@OliverEvans96
Copy link

@Laura-Novich-OBW - you probably want to check out the CSS sections of https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details

@abzrg
Copy link

abzrg commented Nov 21, 2022

$\color{darkgray}\text{Unit}_{\Large1}$

$\textit{\large 1. }\textbf{\color{lightyellow}abroad}$ ( $\textit{\color{darkgray}adv}$ )

  • $\textit{\color{lightblue}I would love to go abroad this year, perhaps to South of France.}$
  • $\textit{\color{lightcyan}...public opposition here and abroad...}$
  • $\textit{\color{lightblue}About 65 per cent of its sales come from abroad.}$
  • Definition

    in or to a foreign country. (= overseas)

$\textit{\large 2. }\textbf{\color{lightyellow}accustomed to}$ ( $\textit{\color{darkgray}adj}$ )

  • $\textit{\color{lightblue}I was accustomed to being the only child at a table full of adults...}$
  • $\textit{\color{lightcyan}We were accustomed to working together.}$
  • $\textit{\color{lightblue}Her eyes quickly became accustomed to the dark.}$
  • Definition

    If you are accustomed to something, you know it so well or have experienced it so often that it seems natural, unsurprising, or easy to deal with.

@mdrahmed
Copy link

mdrahmed commented Jun 9, 2023

click to collapse

this one starts expanded because of the "open"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment