arve0/markdown-it-implicit-figures

Add wrapper around the figure

Closed this issue · 2 comments

Is there a way to somehow easily add wrapper around "figure"?

<div>
  <figure>
    <img src="...">
  </figure>
</div>

I tried something like this, but it doesn't work:

state.tokens[i - 2].type = 'div_open';
state.tokens[i - 2].tag = 'div';

state.tokens[i - 1].type = 'figure_open';
state.tokens[i - 1].tag = 'figure';
state.tokens[i + 1].type = 'figure_close';
state.tokens[i + 1].tag = 'figure';

state.tokens[i + 2].type = 'div_close';
state.tokens[i + 1].tag = 'div';
arve0 commented

Use a custom renderer. You can read about it here: https://github.com/markdown-it/markdown-it/blob/master/docs/architecture.md

Thanks, I'll try 😃