rspress-plugin-mermaid 0.1.1 → 0.1.3-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # rspress-plugin-mermaid ![NPM Version](https://img.shields.io/npm/v/rspress-plugin-mermaid)
2
2
 
3
+ [简体中文](./README.zh-CN.md)
4
+
3
5
  Rspress plugin to render mermaid diagrams in markdown files.
4
6
 
5
7
  Write mermaid as code blocks in markdown files and they will be rendered as SVGs:
@@ -0,0 +1,63 @@
1
+ # rspress-plugin-mermaid ![NPM Version](https://img.shields.io/npm/v/rspress-plugin-mermaid)
2
+
3
+ 为 Rspress 支持基于 [Mermaid](hhttps://mermaid.js.org/#/) 的流程图、时序图等图表。
4
+
5
+ 编写 Mermaid 图表时,只需使用 `mermaid` 代码块,插件会自动将其转换为 SVG。
6
+
7
+ ````markdown
8
+ ```mermaid
9
+ flowchart TD
10
+ A[Christmas] -->|Get money| B(Go shopping)
11
+ B --> C{Let me think}
12
+ C -->|One| D[Laptop]
13
+ C -->|Two| E[iPhone]
14
+ C -->|Three| F[fa:fa-car Car]
15
+ ```
16
+ ````
17
+
18
+ <div align="center">
19
+ <img src="./image.png" alt="sample" width="400" height="560" />
20
+ </div>
21
+
22
+ ## 使用
23
+
24
+ ```bash
25
+ npm i rspress-plugin-mermaid
26
+ pnpm add rspress-plugin-mermaid
27
+ ```
28
+
29
+ ```ts
30
+ import * as path from 'path';
31
+ import { defineConfig } from 'rspress/config';
32
+ import mermaid from 'rspress-plugin-mermaid';
33
+
34
+ export default defineConfig({
35
+ root: path.join(__dirname, 'docs'),
36
+ plugins: [mermaid()],
37
+ });
38
+ ```
39
+
40
+ ## 配置
41
+
42
+ ### mermaidConfig
43
+
44
+ Mermaid 配置选项,将传递给 `mermaid.initialize` 函数。查看 [mermaid 文档](https://mermaid.js.org/config/schema-docs/config.html) 了解更多细节。
45
+
46
+ - Type: `object`
47
+
48
+ ```ts
49
+ import * as path from 'path';
50
+ import { defineConfig } from 'rspress/config';
51
+ import mermaid from 'rspress-plugin-mermaid';
52
+
53
+ export default defineConfig({
54
+ root: path.join(__dirname, 'docs'),
55
+ plugins: [
56
+ mermaid({
57
+ mermaidConfig: {
58
+ theme: 'forest',
59
+ },
60
+ }),
61
+ ],
62
+ });
63
+ ```
package/dist/index.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import path from 'node:path';
2
- import { PresetConfigMutator, RemarkCodeBlockToGlobalComponentPluginFactory, } from 'rspress-plugin-devkit';
2
+ import { PresetConfigMutator, RemarkCodeBlockToGlobalComponentPluginFactory, getCompatComponentPath, } from 'rspress-plugin-devkit';
3
3
  export default function rspressPluginMermaid(options = {}) {
4
4
  const { mermaidConfig = {} } = options;
5
5
  const remarkMermaid = new RemarkCodeBlockToGlobalComponentPluginFactory({
6
6
  components: [
7
7
  {
8
8
  lang: 'mermaid',
9
- componentPath: path.join(__dirname, './components/MermaidRender.tsx'),
9
+ componentPath: path.join(__dirname, './components', getCompatComponentPath(__dirname, 'MermaidRender.tsx')),
10
10
  childrenProvider() {
11
11
  return [];
12
12
  },
package/package.json CHANGED
@@ -1,7 +1,10 @@
1
1
  {
2
2
  "name": "rspress-plugin-mermaid",
3
- "version": "0.1.1",
3
+ "version": "0.1.3-beta.0",
4
4
  "description": "Rspress plugin to render mermaid diagrams",
5
+ "files": [
6
+ "dist"
7
+ ],
5
8
  "keywords": [
6
9
  "rspress",
7
10
  "plugin",
@@ -25,7 +28,7 @@
25
28
  "dependencies": {
26
29
  "@rspress/shared": "^1.17.1",
27
30
  "mermaid": "^10.9.0",
28
- "rspress-plugin-devkit": "^0.1.1"
31
+ "rspress-plugin-devkit": "^0.1.3-beta.0"
29
32
  },
30
33
  "devDependencies": {
31
34
  "@types/node": "^20.12.5",
package/CHANGELOG.md DELETED
@@ -1,19 +0,0 @@
1
- # rspress-plugin-mermaid
2
-
3
- ## 0.1.1
4
-
5
- ### Patch Changes
6
-
7
- - 546dcf0: release beta
8
- - 5e28903: fixup publish config
9
- - Updated dependencies [546dcf0]
10
- - Updated dependencies [5e28903]
11
- - rspress-plugin-devkit@0.1.1
12
-
13
- ## 0.1.1-beta.0
14
-
15
- ### Patch Changes
16
-
17
- - 546dcf0: release beta
18
- - Updated dependencies [546dcf0]
19
- - rspress-plugin-devkit@0.1.1-beta.0
@@ -1 +0,0 @@
1
- [{"id":0,"title":"RSPress x Mermaid","content":"#\n\nMERMAID\n\nflowchart TD\n\nA[Christmas] -->|Get money| B(Go shopping)\n\nB --> C{Let me think}\n\nC -->|One| D[Laptop]\n\nC -->|Two| E[iPhone]\n\nC -->|Three| F[fa:fa-car Car]","routePath":"/","lang":"","toc":[],"domain":"","frontmatter":{},"version":""}]
package/docs/index.md DELETED
@@ -1,10 +0,0 @@
1
- # RSPress x Mermaid
2
-
3
- ```mermaid
4
- flowchart TD
5
- A[Christmas] -->|Get money| B(Go shopping)
6
- B --> C{Let me think}
7
- C -->|One| D[Laptop]
8
- C -->|Two| E[iPhone]
9
- C -->|Three| F[fa:fa-car Car]
10
- ```
package/image.png DELETED
Binary file
package/rspress.config.ts DELETED
@@ -1,9 +0,0 @@
1
- import * as path from 'path';
2
- import { defineConfig } from 'rspress/config';
3
- import mermaid from './src';
4
-
5
- export default defineConfig({
6
- root: path.join(__dirname, 'docs'),
7
- title: 'Rspress x Mermaid Example',
8
- plugins: [mermaid()],
9
- });
@@ -1,55 +0,0 @@
1
- import React, { useEffect, useId, useState } from 'react';
2
-
3
- import mermaid, { type MermaidConfig } from 'mermaid';
4
-
5
- export interface MermaidRendererProps {
6
- code: string;
7
- config?: MermaidConfig;
8
- }
9
-
10
- const MermaidRenderer: React.FC<MermaidRendererProps> = (props) => {
11
- const { code, config = {} } = props;
12
-
13
- const id = useId();
14
-
15
- const [svg, setSvg] = useState('');
16
-
17
- const [renderError, setRenderError] = useState(false);
18
-
19
- async function renderMermaid2SVG() {
20
- // https://github.com/mermaid-js/mermaid/blob/1b40f552b20df4ab99a986dd58c9d254b3bfd7bc/packages/mermaid/src/docs/.vitepress/theme/Mermaid.vue#L53
21
- const hasDarkClass = document.documentElement.classList.contains('dark');
22
-
23
- const mermaidConfig: MermaidConfig = {
24
- securityLevel: 'loose',
25
- startOnLoad: false,
26
- theme: hasDarkClass ? 'dark' : 'default',
27
- ...config,
28
- };
29
-
30
- try {
31
- mermaid.initialize(mermaidConfig);
32
-
33
- const { svg } = await mermaid.render(
34
- id.replace(/:/g, ''),
35
- code as string,
36
- );
37
-
38
- setSvg(svg);
39
- } catch (error) {
40
- setRenderError(true);
41
- }
42
- }
43
-
44
- useEffect(() => {
45
- renderMermaid2SVG();
46
- }, [code]);
47
-
48
- return (
49
- <>
50
- {renderError ? null : <div dangerouslySetInnerHTML={{ __html: svg }} />}
51
- </>
52
- );
53
- };
54
-
55
- export default MermaidRenderer;
package/src/index.ts DELETED
@@ -1,50 +0,0 @@
1
- import path from 'node:path';
2
-
3
- import {
4
- PresetConfigMutator,
5
- RemarkCodeBlockToGlobalComponentPluginFactory,
6
- } from 'rspress-plugin-devkit';
7
-
8
- import type { RspressPlugin } from '@rspress/shared';
9
- import type { MermaidConfig } from 'mermaid';
10
- import type { MermaidRendererProps } from './components/MermaidRender';
11
-
12
- interface RspressPluginMermaidOptions {
13
- mermaidConfig?: MermaidConfig;
14
- }
15
-
16
- export default function rspressPluginMermaid(
17
- options: RspressPluginMermaidOptions = {},
18
- ): RspressPlugin {
19
- const { mermaidConfig = {} } = options;
20
-
21
- const remarkMermaid = new RemarkCodeBlockToGlobalComponentPluginFactory({
22
- components: [
23
- {
24
- lang: 'mermaid',
25
- componentPath: path.join(__dirname, './components/MermaidRender.tsx'),
26
- childrenProvider() {
27
- return [];
28
- },
29
- propsProvider(code) {
30
- return {
31
- code,
32
- config: mermaidConfig,
33
- } satisfies MermaidRendererProps;
34
- },
35
- },
36
- ],
37
- });
38
-
39
- return {
40
- name: 'rspress-plugin-mermaid',
41
- config(config) {
42
- return new PresetConfigMutator(config).disableMdxRs().toConfig();
43
- },
44
- markdown: {
45
- remarkPlugins: [remarkMermaid.remarkPlugin],
46
- globalComponents: remarkMermaid.mdxComponents,
47
- },
48
- builderConfig: remarkMermaid.builderConfig,
49
- };
50
- }
package/tsconfig.json DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "rootDir": "src",
4
- "outDir": "dist"
5
- },
6
- "include": ["src"],
7
- "extends": "../../tsconfig.base.json"
8
- }