1 | const MarkdownIt = require('markdown-it');
|
2 | const hljs = require('highlight.js');
|
3 | const attrs = require('markdown-it-attrs');
|
4 | const containers = require('markdown-it-container');
|
5 | const namedHeadings = require('markdown-it-named-headings');
|
6 |
|
7 | module.exports = MarkdownIt({
|
8 | html: true,
|
9 | highlight: function(s,l){
|
10 | return l && hljs.getLanguage(l) ? hljs.highlight(l,s).value : '';
|
11 | }
|
12 | })
|
13 | .use(attrs)
|
14 | .use(namedHeadings)
|
15 | .use(containers, 'block', {
|
16 | validate: function(){ return true; },
|
17 | render: function([...tokens], idx){
|
18 | if(tokens[idx].type === 'container_block_open'){
|
19 | let className = tokens[idx].info.trim() || 'md-container';
|
20 | return `<${tokens[idx].tag} class="${className}">\n`;
|
21 | } else if (tokens[idx].type === 'container_block_close'){
|
22 | return `</${tokens[idx].tag}>\n`;
|
23 | }
|
24 | }
|
25 | });
|