
Company News
/Security News
Socket Selected for OpenAI's Cybersecurity Grant Program
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.
markdown-it-collapsible
Advanced tools
A markdown-it plugin, which adds collapsibles via the HTML <details> and <summary> elements
A markdown-it plugin, which adds collapsibles via the HTML
<details>and<summary>elements

npm install markdown-it-collapsible
// ESM
import MarkdownIt from "markdown-it";
import MarkdownItCollapsible from "markdown-it-collapsible";
const md = new MarkdownIt().use(MarkdownItCollapsible, options);
// CommonJS
const MarkdownIt = require("markdown-it");
const MarkdownItCollapsible = require("markdown-it-collapsible");
const md = MarkdownIt().use(MarkdownItCollapsible, options);
+++ <visible_text>
<hidden_text>
+++
e.g.
+++ Click me!
Hidden text
+++
is interpreted as
<details>
<summary>
<span class="details-marker"></span>
Click me!
</summary>
<p>
Hidden text
</p>
</details>
To start in open state, use ++> instead:
++> Click me!
Hidden text
++>
You can nest collapsibles by adding more + characters to the outer elements:
## Closed
++++ Click me!
Hidden text
+++ Nested
Inner hidden text
+++
++++
## Open
+++> Click me!
Hidden text
+++ Nested
Inner hidden text
+++
+++>
Modern browsers don't need additional styling. For better UX you can add a few lines of CSS:
summary {
display: flex;
align-items: start;
outline: none;
list-style: none;
user-select: none;
cursor: pointer;
}
summary > h1, summary > h2, summary > h3, summary > h4, summary > h5, summary > h6 {
display: inline-block;
margin: 0;
}
details > *:not(summary) {
margin-top: 0;
margin-bottom: 0.5rem;
margin-left: 1.25rem;
To make the marker scale with headings, an empty span element is created in the parsed HTML. Style the CSS class details-marker in any way you like, for example:
.details-marker::before {
content: "▶︎";
display: inline-block;
margin-right: 0.5ch;
flex-shrink: 0;
transition: 0.3s;
}
details[open] > summary .details-marker::before {
transform: rotate(90deg);
transform-origin: 40% 45% 0;
}
FAQs
A markdown-it plugin, which adds collapsibles via the HTML <details> and <summary> elements
The npm package markdown-it-collapsible receives a total of 2,406 weekly downloads. As such, markdown-it-collapsible popularity was classified as popular.
We found that markdown-it-collapsible demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.

Security News
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.

Research
/Security News
Campaign of 108 extensions harvests identities, steals sessions, and adds backdoors to browsers, all tied to the same C2 infrastructure.