Replies: 5 comments 9 replies
-
You can use their rehype plugin, I think it's not quite necessary to make a wrapper for it. |
Beta Was this translation helpful? Give feedback.
-
@Thijmen Have you been able to get this to work? I tried this is in my import { rehypeCode } from 'fumadocs-core/mdx-plugins';
import { defineConfig, defineDocs } from 'fumadocs-mdx/config';
import rehypeMermaid from 'rehype-mermaid';
export const { docs, meta } = defineDocs({
dir: 'content',
});
export default defineConfig({
mdxOptions: {
rehypePlugins: [rehypeMermaid, rehypeCode],
},
}); and a ---
title: Diagram
---
<pre>
<code class="language-mermaid">
graph TD;
A-->B;
A-->C;
B-->D;
C-->D;
</code>
</pre> No joy for me, I get the actual mermaid text rendered, no image. |
Beta Was this translation helpful? Give feedback.
-
You can use a codeblock instead of JSX elements. And configure it as: export default defineConfig({
mdxOptions: {
rehypePlugins: items => [rehypeMermaid, ...items],
},
}); |
Beta Was this translation helpful? Give feedback.
-
I've also got similar questions on Discord, I'll make a built-in integration soon. For now, you can use the following component with MDX: 'use client';
import mermaid, { type RenderResult } from 'mermaid';
import { type HTMLAttributes, useEffect, useRef, useState } from 'react';
export function Mermaid({
text,
...props
}: Omit<HTMLAttributes<HTMLDivElement>, 'children'> & {
text: string;
}) {
const ref = useRef<HTMLDivElement>(null);
const [rendered, setRendered] = useState<RenderResult>();
useEffect(() => {
async function run() {
const element = ref.current;
if (!element) return;
mermaid.initialize({
theme: 'dark',
});
const result = await mermaid.render(props.id ?? 'mermaid', text, element);
setRendered(result);
result.bindFunctions?.(element);
}
void run();
}, [props.id, text]);
return (
<div
ref={ref}
dangerouslySetInnerHTML={rendered ? { __html: rendered.svg } : undefined}
{...props}
/>
);
} |
Beta Was this translation helpful? Give feedback.
-
Thank you both for the quick replies! |
Beta Was this translation helpful? Give feedback.
-
Hi there,
I love your product - is there any chance for Mermaid support in the near future? See also https://mermaid.js.org/
Beta Was this translation helpful? Give feedback.
All reactions