ssssota / svelte-exmarkdown

Svelte component to render markdown.
https://ssssota.github.io/svelte-exmarkdown
MIT License
168 stars 5 forks source link

Adding mermaid plugin #52

Open vlrevolution opened 1 year ago

vlrevolution commented 1 year ago

Is there any way to add mermaid support?

Perhaps with this: https://github.com/remcohaszing/rehype-mermaidjs

longnguyen2004 commented 12 months ago

You can look at the Plugin type and the gfm plugin wrapper to see how to add a plugin yourself

vlrevolution commented 12 months ago

Thank you, I realized that it is simpler than it seemed at first. I will try soon!

abdelaliz commented 9 months ago

I am also trying to get this to work but am still struggling with initializing the plugin properly. How can one pass an options object to a rehype plugin?

I might be wrong, but the createParser method does not seem to take plugins options into consideration

export const createParser = (plugins: Plugin[]): Parser => {
    const processor = unified()
        .use(remarkParse)
        .use(plugins.map((plugin) => plugin.remarkPlugin).filter(nonNullable))
        .use(remarkRehype, { allowDangerousHtml: true })
        .use(plugins.map((plugin) => plugin.rehypePlugin).filter(nonNullable))
        .use(rehypeReactClassNameToSvelteClass);
    return (md: string) => processor.runSync(processor.parse(md), md);
};
longnguyen2004 commented 9 months ago

You supply the option as the 2nd array element https://github.com/ssssota/svelte-exmarkdown/blob/98af8a6455875da21d8759d7650accc8b8058ad3/src/lib/gfm/index.ts#L5