rspress-plugin-mermaid 0.1.0 → 0.1.2-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/CHANGELOG.md ADDED
@@ -0,0 +1,27 @@
1
+ # rspress-plugin-mermaid
2
+
3
+ ## 0.1.2-beta.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 932dbb7: compat component path
8
+ - Updated dependencies [932dbb7]
9
+ - rspress-plugin-devkit@0.1.2-beta.0
10
+
11
+ ## 0.1.1
12
+
13
+ ### Patch Changes
14
+
15
+ - 546dcf0: release beta
16
+ - 5e28903: fixup publish config
17
+ - Updated dependencies [546dcf0]
18
+ - Updated dependencies [5e28903]
19
+ - rspress-plugin-devkit@0.1.1
20
+
21
+ ## 0.1.1-beta.0
22
+
23
+ ### Patch Changes
24
+
25
+ - 546dcf0: release beta
26
+ - Updated dependencies [546dcf0]
27
+ - rspress-plugin-devkit@0.1.1-beta.0
package/README.md CHANGED
@@ -1,4 +1,6 @@
1
- # rspress-plugin-mermaid
1
+ # rspress-plugin-mermaid ![NPM Version](https://img.shields.io/npm/v/rspress-plugin-mermaid)
2
+
3
+ [简体中文](./README.zh-CN.md)
2
4
 
3
5
  Rspress plugin to render mermaid diagrams in markdown files.
4
6
 
@@ -16,7 +18,7 @@ flowchart TD
16
18
  ````
17
19
 
18
20
  <div align="center">
19
- <img src="./image.png" alt="sample" width="400" height="550" />
21
+ <img src="./image.png" alt="sample" width="400" height="560" />
20
22
  </div>
21
23
 
22
24
  ## Usage
@@ -52,10 +54,12 @@ import mermaid from 'rspress-plugin-mermaid';
52
54
 
53
55
  export default defineConfig({
54
56
  root: path.join(__dirname, 'docs'),
55
- plugins: [mermaid({
56
- mermaidConfig: {
57
- theme: 'forest',
58
- },
59
- })],
57
+ plugins: [
58
+ mermaid({
59
+ mermaidConfig: {
60
+ theme: 'forest',
61
+ },
62
+ }),
63
+ ],
60
64
  });
61
- ```
65
+ ```
@@ -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,10 +1,9 @@
1
1
  import path from 'node:path';
2
- import { CodeBlock2GlobalComponentPluginFactory } from 'rspress-plugin-devkit';
2
+ import { PresetConfigMutator, RemarkCodeBlockToGlobalComponentPluginFactory, } from 'rspress-plugin-devkit';
3
3
  export default function rspressPluginMermaid(options = {}) {
4
4
  const { mermaidConfig = {} } = options;
5
- return new CodeBlock2GlobalComponentPluginFactory({
6
- name: 'rspress-plugin-mermaid',
7
- transformers: [
5
+ const remarkMermaid = new RemarkCodeBlockToGlobalComponentPluginFactory({
6
+ components: [
8
7
  {
9
8
  lang: 'mermaid',
10
9
  componentPath: path.join(__dirname, './components/MermaidRender.tsx'),
@@ -19,5 +18,16 @@ export default function rspressPluginMermaid(options = {}) {
19
18
  },
20
19
  },
21
20
  ],
22
- }).instantiate();
21
+ });
22
+ return {
23
+ name: 'rspress-plugin-mermaid',
24
+ config(config) {
25
+ return new PresetConfigMutator(config).disableMdxRs().toConfig();
26
+ },
27
+ markdown: {
28
+ remarkPlugins: [remarkMermaid.remarkPlugin],
29
+ globalComponents: remarkMermaid.mdxComponents,
30
+ },
31
+ builderConfig: remarkMermaid.builderConfig,
32
+ };
23
33
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rspress-plugin-mermaid",
3
- "version": "0.1.0",
3
+ "version": "0.1.2-beta.0",
4
4
  "description": "Rspress plugin to render mermaid diagrams",
5
5
  "keywords": [
6
6
  "rspress",
@@ -19,15 +19,18 @@
19
19
  "author": "Linbudu <linbudu599@gmail.com> (https://github.com/linbudu599)",
20
20
  "main": "dist/index.js",
21
21
  "types": "dist/index.d.ts",
22
+ "publishConfig": {
23
+ "access": "public"
24
+ },
22
25
  "dependencies": {
23
- "@rspress/shared": "^1.16.2",
26
+ "@rspress/shared": "^1.17.1",
24
27
  "mermaid": "^10.9.0",
25
- "rspress-plugin-devkit": "^0.1.0"
28
+ "rspress-plugin-devkit": "^0.1.2-beta.0"
26
29
  },
27
30
  "devDependencies": {
28
- "@types/node": "^20.12.2",
29
- "@types/react": "^18.2.73",
30
- "typescript": "^5"
31
+ "@types/node": "^20.12.5",
32
+ "@types/react": "^18.2.74",
33
+ "typescript": "^5.4.4"
31
34
  },
32
35
  "peerDependencies": {
33
36
  "rspress": "*"
@@ -36,7 +39,6 @@
36
39
  "build": "tsc --declarationMap false",
37
40
  "dev": "tsc -w",
38
41
  "docs:build": "rspress build",
39
- "docs:dev": "rspress dev",
40
- "prepublish": "npm run build"
42
+ "docs:dev": "rspress dev"
41
43
  }
42
44
  }
package/src/index.ts CHANGED
@@ -1,6 +1,10 @@
1
1
  import path from 'node:path';
2
2
 
3
- import { CodeBlock2GlobalComponentPluginFactory } from 'rspress-plugin-devkit';
3
+ import {
4
+ PresetConfigMutator,
5
+ RemarkCodeBlockToGlobalComponentPluginFactory,
6
+ getCompatComponentPath,
7
+ } from 'rspress-plugin-devkit';
4
8
 
5
9
  import type { RspressPlugin } from '@rspress/shared';
6
10
  import type { MermaidConfig } from 'mermaid';
@@ -15,12 +19,15 @@ export default function rspressPluginMermaid(
15
19
  ): RspressPlugin {
16
20
  const { mermaidConfig = {} } = options;
17
21
 
18
- return new CodeBlock2GlobalComponentPluginFactory({
19
- name: 'rspress-plugin-mermaid',
20
- transformers: [
22
+ const remarkMermaid = new RemarkCodeBlockToGlobalComponentPluginFactory({
23
+ components: [
21
24
  {
22
25
  lang: 'mermaid',
23
- componentPath: path.join(__dirname, './components/MermaidRender.tsx'),
26
+ componentPath: path.join(
27
+ __dirname,
28
+ './components',
29
+ getCompatComponentPath(__dirname, 'MermaidRender.tsx'),
30
+ ),
24
31
  childrenProvider() {
25
32
  return [];
26
33
  },
@@ -32,5 +39,17 @@ export default function rspressPluginMermaid(
32
39
  },
33
40
  },
34
41
  ],
35
- }).instantiate();
42
+ });
43
+
44
+ return {
45
+ name: 'rspress-plugin-mermaid',
46
+ config(config) {
47
+ return new PresetConfigMutator(config).disableMdxRs().toConfig();
48
+ },
49
+ markdown: {
50
+ remarkPlugins: [remarkMermaid.remarkPlugin],
51
+ globalComponents: remarkMermaid.mdxComponents,
52
+ },
53
+ builderConfig: remarkMermaid.builderConfig,
54
+ };
36
55
  }