markdown-it / markdown-it-container

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

Multiline complex container? #25

Closed chris-dura closed 6 years ago

chris-dura commented 6 years ago

Hello, I've looked through the documentation, and I'm having a hard time figuring out how to do what I need. I think part of the problem is that the example only works when the markdown is all on a singleline, but the other example is on multilines:

::: warning
*here be dragons*
:::

Basically, with the following:

::: warning
## Beware!
*here be dragons*
_seriously, there are._
:::

I'd like to render out the following HTML:

<div class="warning">
  <div class="left-col"><h2>Beware!</h2></div>
  <div class="middle"><em>here be dragons</em></div>
  <div class="right"><em>seriously, there are.</em></div>
</div>
chris-dura commented 6 years ago

It seems that when passing a multiline the tokens[idx].info only has the first line, and not the content of the container...

::: spoiler click me\n*content*\n:::

::: warning
*here be dragons*
:::

var md = require('markdown-it')();

md.use(require('markdown-it-container'), 'spoiler', {
  ...
  render: function (tokens, idx) {
    console.log(tokens[idx].info); // output: spoiler click me\n*content*\n:::
    ...
  }
})
.use(require('markdown-it-container'), 'warning', {
  ...
  render: function (tokens, idx) {
    console.log(tokens[idx].info); // output: warning
    ...
  }
});
puzrin commented 6 years ago

If you need nesting:

::: warning
:::: left-col
::::
:::: middle
::::
:::: right
::::
:::

Principle is the same as with fenced blocks - vary delimiter length.