开源软件名称(OpenSource Name):markdown-it/markdown-it-container开源软件地址(OpenSource Url):https://github.com/markdown-it/markdown-it-container开源编程语言(OpenSource Language):JavaScript 89.2%开源软件介绍(OpenSource Introduction):markdown-it-container
v2.+ requires With this plugin you can create block containers like:
.... and specify how they should be rendered. If no renderer defined, <div class="warning">
<em>here be dragons</em>
</div> Markup is the same as for fenced code blocks. Difference is, that marker use another character and content is rendered as markdown markup. Installationnode.js, browser: $ npm install markdown-it-container --save
$ bower install markdown-it-container --save APIvar md = require('markdown-it')()
.use(require('markdown-it-container'), name [, options]); Params:
Examplevar md = require('markdown-it')();
md.use(require('markdown-it-container'), 'spoiler', {
validate: function(params) {
return params.trim().match(/^spoiler\s+(.*)$/);
},
render: function (tokens, idx) {
var m = tokens[idx].info.trim().match(/^spoiler\s+(.*)$/);
if (tokens[idx].nesting === 1) {
// opening tag
return '<details><summary>' + md.utils.escapeHtml(m[1]) + '</summary>\n';
} else {
// closing tag
return '</details>\n';
}
}
});
console.log(md.render('::: spoiler click me\n*content*\n:::\n'));
// Output:
//
// <details><summary>click me</summary>
// <p><em>content</em></p>
// </details> License |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论