다이어그램
Diagrams can be rendered using Mermaid in a code block.
설치
- npm
- Yarn
- pnpm
- Bun
npm install --save @docusaurus/theme-mermaid
yarn add @docusaurus/theme-mermaid
pnpm add @docusaurus/theme-mermaid
bun add @docusaurus/theme-mermaid
Enable Mermaid functionality by adding plugin @docusaurus/theme-mermaid and setting markdown.mermaid to true in your docusaurus.config.js.
export default {
markdown: {
mermaid: true,
},
themes: ['@docusaurus/theme-mermaid'],
};
사용법
Add a code block with language mermaid:
```mermaid
graph TD;
A-->B;
A-->C;
B-->D;
C-->D;
```
See the Mermaid syntax documentation for more information on the Mermaid syntax.
테마
The diagram dark and light themes can be changed by setting mermaid.theme values in the themeConfig in your docusaurus.config.js. 어두운 테마와 밝은 테마를 아래와 같이 설정할 수 있습니다.
export default {
themeConfig: {
mermaid: {
theme: {light: 'neutral', dark: 'forest'},
},
},
};
See the Mermaid theme documentation for more information on theming Mermaid diagrams.
Mermaid 구성 옵션
Options in mermaid.options will be passed directly to mermaid.initialize:
export default {
themeConfig: {
mermaid: {
options: {
maxTextSize: 50,
},
},
},
};
See the Mermaid config documentation and the Mermaid config types for the available config options.
Dynamic Mermaid Component
To generate dynamic diagrams, you can use the Mermaid component:
import Mermaid from '@theme/Mermaid';
<Mermaid
value={`graph TD;
A-->B;
A-->C;
B-->D;
C-->D;`}
/>
Layouts
Mermaid supports different layout engines:
- The
elklayout engine is bundled and used by default for supported diagram types. - The
dagrelayout engine is also bundled and can be selected explicitly.
Site-wide layout
To use Dagre across your site, set themeConfig.mermaid.options.layout:
export default {
themeConfig: {
mermaid: {
options: {
layout: 'dagre',
},
},
},
};
Per-diagram layout
To use Dagre for a single diagram, set layout: dagre in its Mermaid front matter. This overrides the site-wide layout. Use layout: elk to select ELK explicitly.
```mermaid
---
config:
layout: dagre
---
graph TD;
A-->B;
A-->C;
B-->D;
C-->D;
```
The same diagram rendered with each layout:
ELK (default)
Dagre