markdown-it / markdown-it-container

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

How can I customize the rendering of content inside block? #17

Closed sidvishnoi closed 7 years ago

sidvishnoi commented 7 years ago

I'm trying to make a markdown-it tabs plugin.

::: tabs SOME_ID

# tab1 title
tab1 content

---

#tab2 title
tab2 **content**

:::

How can I control the rendering of the content inside the custom block?

I want the output as:

<div class="md-tabs" id="SOME_ID">
  <ul>
    <li><a href="#SOME_ID_tab1-title">tab1 title</a></li>
    <li><a href="#SOME_ID_tab2-title">tab2 title</a></li>
  </ul>

  <div class="tab" id="SOME_ID_tab1-title">
    <h1>tab1 title</h1>
    <div class="tab-content">
      <p>tab 1 content</p>
    </div>
  </div>
  <div class="tab" id="SOME_ID_tab2-title">
    <h1>tab2 title</h1>
    <div class="tab-content">
      <p>tab 2 <strong>content</strong></p>
    </div>
  </div>

</div>
puzrin commented 7 years ago

How can I control the rendering of the content inside the custom block?

You can't, except define nested css selectors. This package is to create wrapper "div"-s and leave inner intack.

oravecz commented 5 years ago

Came across this as I was beginning to write the same functionality for tabs. Is it not possible in the render function to modify the tokens array to conform to any structure I might need to achieve the proper results?

I am tracking the index of my container_tabs_open token type, and when I receive my container_tabs_close callback, I now have the span of tokens that I would like to manipulate completely. Can I not delete all the tokens in that range and insert new tokens as I wish?

puzrin commented 5 years ago

It would be a very bad design idea to modify foreign tokens from renderer. Because this will break border of abstraction layer. Add plugin to the end of core chain instead. Also check twice, if you use this plugin according to it's intent. Probably, you may wish customized fenced block, if you need to modify content.

I can't say exactly, because have no details about your needs. But request to modify container content looks strange in scope of this package.