Skip to content

feat(md): support mermaid #7544

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions apps/site/components/__design__/mermaid.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type { Meta as MetaObj, StoryObj } from '@storybook/react';
import dedent from 'dedent';
import { VFile } from 'vfile';

import { compile } from '@/next.mdx.compiler.mjs';

type Props = { children: string };

type Story = StoryObj<Props>;
type Meta = MetaObj<Props>;

export const Mermaid: Story = {
args: {
children: dedent`\`\`\`mermaid
graph LR
A[Client] --> B(Load Balancer)
B --> C{Server 1}
B --> D{Server 2}
\`\`\``,
},
};

export default {
title: 'Design System',
render: (_, { loaded: { Content } }) => Content,
loaders: [
async ({ args }) => {
const { content } = await compile(new VFile(args.children), 'mdx', {});

return { Content: content };
},
],
} as Meta;
4 changes: 4 additions & 0 deletions apps/site/next.mdx.plugins.mjs
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@

import remarkHeadings from '@vcarl/remark-headings';
import rehypeAutolinkHeadings from 'rehype-autolink-headings';
import rehypeMermaid from 'rehype-mermaid';
import rehypeSlug from 'rehype-slug';
import remarkGfm from 'remark-gfm';
import readingTime from 'remark-reading-time';
@@ -14,6 +15,9 @@ import rehypeShikiji from './next.mdx.shiki.mjs';
* @type {Array<import('unified').Plugin>}
*/
export const REHYPE_PLUGINS = [
// Transforms Mermaid code blocks into SVGs
// note: needs to be imported before rehype-shiki to prevent transforming into code-blocks
[rehypeMermaid, { strategy: 'inline-svg', dark: true }],
// Generates `id` attributes for headings (H1, ...)
rehypeSlug,
// Automatically add anchor links to headings (H1, ...)
9 changes: 9 additions & 0 deletions apps/site/package.json
Original file line number Diff line number Diff line change
@@ -56,6 +56,7 @@
"next": "15.2.0",
"next-intl": "~3.26.5",
"next-themes": "~0.4.4",
"playwright": "^1.51.0",
"postcss": "~8.5.3",
"postcss-calc": "~10.1.1",
"postcss-import": "~16.1.0",
@@ -65,6 +66,7 @@
"react": "19.0.0",
"react-dom": "19.0.0",
"rehype-autolink-headings": "~7.1.0",
"rehype-mermaid": "^3.0.0",
"rehype-slug": "~6.0.0",
"remark-gfm": "~4.0.1",
"remark-reading-time": "~2.0.1",
@@ -111,5 +113,12 @@
"typescript": "~5.7.2",
"typescript-eslint": "~8.25.0",
"user-agent-data-types": "0.4.2"
},
"overrides": {
"rehype-mermaid": {
"dependencies": {
"mermaid-isomorphic": "*"
}
}
}
}
24,833 changes: 13,524 additions & 11,309 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@
"scripts": {
"dev": "turbo run dev",
"build": "turbo run build",
"storybook": "turbo run storybook",
"storybook:build": "turbo run storybook:build",
"start": "turbo run start",
"check-types": "turbo check-types",
18 changes: 18 additions & 0 deletions packages/mermaid-isomorphic/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# MIT License

Copyright © 2023 Remco Haszing

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the “Software”), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial
portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 changes: 19 additions & 0 deletions packages/mermaid-isomorphic/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import importX from 'eslint-plugin-import-x';
import tseslint from 'typescript-eslint';

// eslint-disable-next-line no-relative-import-paths/no-relative-import-paths
import baseConfig from '../../eslint.config.js';

export default [
...baseConfig,
...tseslint.configs.recommended,
importX.flatConfigs.typescript,
{
ignores: ['dist'],
},
{
rules: {
'@typescript-eslint/consistent-type-imports': 'error',
},
},
];
10 changes: 10 additions & 0 deletions packages/mermaid-isomorphic/fixtures/accessibility/browser.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions packages/mermaid-isomorphic/fixtures/accessibility/expected.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions packages/mermaid-isomorphic/fixtures/accessibility/firefox.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
graph LR
accTitle: Big Decisions
accDescr: Bob's Burgers process for making big decisions
A[Identify Big Descision] --> B{Make Big Decision}
B --> D[Be done]
10 changes: 10 additions & 0 deletions packages/mermaid-isomorphic/fixtures/accessibility/webkit.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading