如何在渲染中包含 vue 组件?在我的例子中,vue 组件是 demo-block,我将它全局包含在 main.js 中。
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+(.*)$/)
if (tokens[idx].nesting === 1) {
const description = m && m.length > 1 ? m[1] : ''
const content = tokens[idx + 1].type === 'fence' ? tokens[idx + 1].content : ''
return `<demo-block><div>${md.render(description)}</div>${content}`
}
return '</demo-block>'
}
})
此代码直接打印标签<demo-block>
而不是 vue 组件。
谢谢。