Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to create a toggle (switch) in MarkDown?

I want to achieve something like this for a documentation that is written with MarkDown:enter image description here

The toggle will show this sample code either in Objective-C or Swift. I couldn't find anything in MD's documentation that shows that this is possible. Any suggestions?

like image 265
Dani Avatar asked Mar 23 '26 02:03

Dani


2 Answers

It is possible with GitHub-flavored markdown in 2021

To make a toggle switch just write this HTML markup in your markdown file(HTML is supported in .md files):

<details>
    <summary>Toggle Switch</summary>
    Foldable Content[enter image description here][1]
</details>

In the above markup, the content inside <details> tag would be foldable(can be toggled) and the content inside <summary> tag would be taken as the content of the toggle button.

like image 89
Hargunbeer Singh Avatar answered Mar 25 '26 22:03

Hargunbeer Singh


This is not possible with regular Markdown or GitHub-flavoured Markdown.

Markdown, generally, outputs HTML. The language itself is deliberately very simple:

Markdown is not a replacement for HTML, or even close to it. Its syntax is very small, corresponding only to a very small subset of HTML tags ... The idea for Markdown is to make it easy to read, write, and edit prose.

What you want to do needs JavaScript.

You could potentially write some JavaScript that works with your Markdown output, though depending on where you plan to host the HTML you may have trouble with that, too.

like image 36
Chris Avatar answered Mar 25 '26 22:03

Chris