Skip to content

Instantly share code, notes, and snippets.

@uncenter
Last active December 5, 2023 16:01
Show Gist options
  • Save uncenter/5db09920e8fe879c38e96e59b2367895 to your computer and use it in GitHub Desktop.
Save uncenter/5db09920e8fe879c38e96e59b2367895 to your computer and use it in GitHub Desktop.
Use any class for markdown-it-container instead of just a single one.
const markdownItContainer = require('markdown-it-container');
const markdownIt = require('markdown-it');
const md = new markdownIt().use(markdownItContainer, 'dynamic', {
validate: function () {
return true;
},
render: function (tokens, idx) {
const token = tokens[idx];
return token.nesting === 1
? '<div class="' + token.info.trim() + '">'
: '</div>';
},
});
console.log(
md.render(`
::: my-dynamic-block
Hello, world!
:::`),
);
@rauschma
Copy link

rauschma commented Dec 5, 2023

Got it. Thanks!

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