vue-markdown-render icon indicating copy to clipboard operation
vue-markdown-render copied to clipboard

How to handle plugin options?

Open SaulSilver opened this issue 2 years ago • 2 comments

Thank you for the nice package. This isn't an issue, but didn't where else to post it. I wanted to share with those who wanted to do the same as I did and save their time.

I wanted to extend @AlextheYounga implementation of allowing plugins to also handle the plugins' options (not to confuse with markdown-it options).

For me, I wanted to add an option to the markdown-it-anchor that I pass as a plugin to vue-markdown-renderer, and override the default slugify function. So I did the following in the :

<script>
const customSlugify = ...;

const anchorPlugin = (vueMarkdownItInstance: MarkdownIt) => {
  vueMarkdownItInstance.use(MarkdownItAnchor, {
    slugify: customSlugify
  });
};

const plugins = [anchorPlugin, /* other plugins */];
<script>

And then I just pass the plugins to vue-markdown-renderer in the

SaulSilver avatar Dec 13 '23 05:12 SaulSilver

function options(plugin, options){
    return (instance) => instance.use(plugin, options)
}

Now: const plugins = options(MarkdownItAnchor, {opts here})

Explosion-Scratch avatar May 28 '24 19:05 Explosion-Scratch

@Explosion-Scratch your version seams nice - how about a list of plugins?

s-light avatar Oct 16 '24 22:10 s-light