4.0.0 • Published 4 months ago

markdown-it-container v4.0.0

Weekly downloads
179,527
License
MIT
Repository
github
Last release
4 months ago

markdown-it-container

CI NPM version Coverage Status

Plugin for creating block-level custom containers for markdown-it markdown parser.

v2.+ requires markdown-it v5.+, see changelog.

With this plugin you can create block containers like:

::: warning
*here be dragons*
:::

.... and specify how they should be rendered. If no renderer defined, <div> with container name class will be created:

<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.

Installation

node.js, browser:

$ npm install markdown-it-container --save
$ bower install markdown-it-container --save

API

var md = require('markdown-it')()
            .use(require('markdown-it-container'), name [, options]);

Params:

  • name - container name (mandatory)
  • options:
    • validate - optional, function to validate tail after opening marker, should return true on success.
    • render - optional, renderer function for opening/closing tokens.
    • marker - optional (:), character to use in delimiter.

Example

var 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

MIT

vuepress-plugin-dice-roller@abpx/docdafunda-markdown-editor@wxzhang/md2vue-loaderzing1-ui@kellywang/edenred-ui@zy524223270/yh-uiaws-vue-uivi-elment-vuecm-chart1vvui-yx-vui-yang@heyform/validatormetta-editorlzhuipkpmgispkpmgisadoc-the-libvitepress-dg@tungcv/markdown-it-vue-minifyvue3-relaxpluswesi-mde@hongbin-npm/dnui@stellaris/react-rich-editorsone-ui@jackluson/uibebras-mdxuuukavenuihy-element-uisamlaxa12sj21obalsaui-nkicarephone@evorto/lexicaroninwz-uiefly-ui3.0hou-markdownvitepress-for-component-custom@nkjmsss/bend_editorstc-md-editorkontenbase-document-editorlxd-uimeitq-element@everseenflash/pen-middlewarelluivite-plugin-ddocvlib-docsifyvue-minor-uixh_pluginsberserk-plugin-content-managerxtm-uivmapuinubo-sitesrich-ui-vuejoysuch_cli3nnuijane-xyz-element@everything-registry/sub-chunk-2132vuepress-plugin-preview-edit2ggg3@vitepress-demo/pluginsxyz-vue-markdownxyz-vue-md-zpvite-plugin-markdown-itice-markdowntic-components-vue2@v-town/weitang-web-pc-comonent@duhaha/editorw-ui-next@ampolon/rich-markdown-editor-v2@aomao/plugin-lightblock@aomao/plugin-mulit-codeblock@apathia/vitepress-theme@archguard/archdoc-editor@akemona-org/strapi-plugin-content-manageraglio-theme-attributable@akord/rich-markdown-editor@yuci/vitepress-markdown-demo-block@11in/scribe@anejs/anne-plugin-docs@angxuejian/md-loader@dangojs/vitepress-theme-demoblockcaptains-blog@dirkdev98/vitepress@dking/markdown-webpack-loadercebuicdcomponentscdcomponents-npmdemo@dmed256/murky@doczen/doczenckg-ui@dopro/docsmaker@deskpro/content-editorchezhibaouichinaedu-uichl-ui-vue3@digicms/admin@digicommerce/cms-adminchromeos-dev-markdowncherryx-ui
4.0.0

4 months ago

3.0.0

4 years ago

2.0.0

9 years ago

1.0.0

9 years ago