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 '' + md.utils.escapeHtml(m[1]) + '\n'; } else { // closing tag return '\n'; } } }); } })