Skip to content

Commit d997fff

Browse files
feat(md): support mermaid
1 parent 8124f8d commit d997fff

File tree

5 files changed

+2701
-698
lines changed

5 files changed

+2701
-698
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import type { Meta as MetaObj, StoryObj } from '@storybook/react';
2+
import dedent from 'dedent';
3+
import { VFile } from 'vfile';
4+
5+
import { compile } from '@/next.mdx.compiler.mjs';
6+
7+
type Props = { children: string };
8+
9+
type Story = StoryObj<Props>;
10+
type Meta = MetaObj<Props>;
11+
12+
export const Mermaid: Story = {
13+
args: {
14+
children: dedent`\`\`\`mermaid
15+
graph LR
16+
A[Client] --> B(Load Balancer)
17+
B --> C{Server 1}
18+
B --> D{Server 2}
19+
\`\`\``,
20+
},
21+
};
22+
23+
export default {
24+
title: 'Design System',
25+
render: (_, { loaded: { Content } }) => Content,
26+
loaders: [
27+
async ({ args }) => {
28+
const { content } = await compile(new VFile(args.children), 'mdx', {});
29+
30+
return { Content: content };
31+
},
32+
],
33+
} as Meta;

apps/site/next.mdx.plugins.mjs

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import remarkHeadings from '@vcarl/remark-headings';
44
import rehypeAutolinkHeadings from 'rehype-autolink-headings';
5+
import rehypeMermaid from 'rehype-mermaid';
56
import rehypeSlug from 'rehype-slug';
67
import remarkGfm from 'remark-gfm';
78
import readingTime from 'remark-reading-time';
@@ -14,6 +15,9 @@ import rehypeShikiji from './next.mdx.shiki.mjs';
1415
* @type {Array<import('unified').Plugin>}
1516
*/
1617
export const REHYPE_PLUGINS = [
18+
// Transforms Mermaid code blocks into SVGs
19+
// note: needs to be imported before rehype-shiki to prevent transforming into code-blocks
20+
[rehypeMermaid, { strategy: 'inline-svg', dark: true }],
1721
// Generates `id` attributes for headings (H1, ...)
1822
rehypeSlug,
1923
// Automatically add anchor links to headings (H1, ...)

apps/site/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"next": "15.2.0",
5757
"next-intl": "~3.26.5",
5858
"next-themes": "~0.4.4",
59+
"playwright": "^1.51.0",
5960
"postcss": "~8.5.3",
6061
"postcss-calc": "~10.1.1",
6162
"postcss-import": "~16.1.0",
@@ -65,6 +66,7 @@
6566
"react": "19.0.0",
6667
"react-dom": "19.0.0",
6768
"rehype-autolink-headings": "~7.1.0",
69+
"rehype-mermaid": "^3.0.0",
6870
"rehype-slug": "~6.0.0",
6971
"remark-gfm": "~4.0.1",
7072
"remark-reading-time": "~2.0.1",

0 commit comments

Comments
 (0)