markdown-it-container

vite 插件中配置

 

 Markdown({
      markdownItOptions: {
        highlight: function (str, lang) {
          if (lang && hljs.getLanguage(lang)) {
            try {
              return hljs.highlight(lang, str).value;
            } catch (__) {}
          }

          return ''; // 使用额外的默认转义
        }
      },
      markdownItSetup(md) {
        md.use(require('markdown-it-container'), 'demo', {
          validate: function (params) {
            return params.trim().match(/^demo\s*(.*)$/);
          },
          render: function (tokens, idx) {
            const m = tokens[idx].info.trim().match(/^demo\s*(.*)$/);
            console.log(m);
            if (tokens[idx].nesting === 1) {
              // opening tag
              return '<div class="box">' + md.utils.escapeHtml(m[1]) + '\n';
            } else {
              // closing tag
              return '</div>\n';
            }
          }
        });
      }
    })

 

posted @ 2021-12-21 21:13  小猪冒泡  阅读(1103)  评论(0编辑  收藏  举报