markdown-it / markdown-it-container

Fenced container plugin for markdown-it markdown parser
MIT License
496 stars 74 forks source link

how could I custome the tag name #16

Closed scil closed 7 years ago

scil commented 7 years ago

I want to control the tag name of rendered html, e.g. z-deep/section instead of div.

        .use(require('markdown-it-container'), 'decorate' , {
            validate: function(params) {
                return params.trim().match(/^(z-deep|section)$/);
            },

            render: function (tokens, idx) {
                var m = tokens[idx].info.trim().match(/^(z-deep|section)$/);

                var tag=m[1]||'div';

                if (tokens[idx].nesting === 1) {
                    // opening tag

                    return '<' + tag  + ' >\n';

                } else {
                    // closing tag
                    console.log('tag ',tag)
                    return '</'+tag+'>\n';
                }
            }

but the closing tag always is 'div', for example

::: z-deep
ok
:::

output:

<z-deep>
<p>ok</p>
</div>
puzrin commented 7 years ago

Your regexp doesn't match closing tag and you use div then. You can add console.log to renderer and see what happens.