Skip to content

Instantly share code, notes, and snippets.

@omartrigui
Created July 28, 2023 12:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save omartrigui/9acec5ad30fad9d5459e3f47b2b2d347 to your computer and use it in GitHub Desktop.
Save omartrigui/9acec5ad30fad9d5459e3f47b2b2d347 to your computer and use it in GitHub Desktop.
Add a collapsible section in markdown

How to add a collapsible section in markdown.

Example

Click me

Some Code

package main

import "fmt"

func mayPanic() {
    panic("a problem")
}

func main() {

    defer func() {
        if r := recover(); r != nil {

            fmt.Println("Recovered. Error:\n", r)
        }
    }()

    mayPanic()

    fmt.Println("After mayPanic()")
}

Code

<details>
  <summary>Click me</summary>
  
  ### Some Code
  ```golang
  package main
  import "fmt"
  func main() {
      fmt.Println("Hello, World!")
  }
  ```
</details>

Rules (If you don't do this, your code may not work)

  1. Always have an empty line after the </summary> tag
  2. Always have an empty line after each </details> tag
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment