2019-11-19 20:13:50 +08:00
|
|
|
const mdContainer = require('markdown-it-container');
|
|
|
|
|
|
|
|
module.exports = md => {
|
2019-11-23 20:10:47 +08:00
|
|
|
md.use(mdContainer, 'demo', {
|
|
|
|
validate(params) {
|
|
|
|
return params.trim().match(/^demo\s*(.*)$/);
|
|
|
|
},
|
|
|
|
render(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>
|
|
|
|
${description ? `<div>${md.render(description)}</div>` : ''}
|
|
|
|
<!--element-demo: ${content}:element-demo-->
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
return '</demo-block>';
|
|
|
|
}
|
|
|
|
});
|
2019-11-19 20:13:50 +08:00
|
|
|
|
2019-11-23 20:10:47 +08:00
|
|
|
md.use(mdContainer, 'tip');
|
|
|
|
md.use(mdContainer, 'warning');
|
|
|
|
};
|