Skip to content

Commit 29d30ff

Browse files
WIP
1 parent 8124f8d commit 29d30ff

File tree

4 files changed

+1563
-47
lines changed

4 files changed

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

apps/site/next.mdx.plugins.mjs

Lines changed: 4 additions & 0 deletions
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+
// !!! This plugin must be before `rehypeShikiji` !!!
20+
rehypeMermaid,
1721
// Generates `id` attributes for headings (H1, ...)
1822
rehypeSlug,
1923
// Automatically add anchor links to headings (H1, ...)

apps/site/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"react": "19.0.0",
6666
"react-dom": "19.0.0",
6767
"rehype-autolink-headings": "~7.1.0",
68+
"rehype-mermaid": "^3.0.0",
6869
"rehype-slug": "~6.0.0",
6970
"remark-gfm": "~4.0.1",
7071
"remark-reading-time": "~2.0.1",

0 commit comments

Comments
 (0)