Browse Source

use PLANTUML_URI and apply to other renderers

Yuki Takei 3 years ago
parent
commit
62ac511f19

+ 12 - 0
packages/app/src/services/renderer/remark-plugins/plantuml.ts

@@ -0,0 +1,12 @@
+import plantuml from '@akebifiky/remark-simple-plantuml';
+import { Plugin } from 'unified';
+
+type PlantUMLPluginParams = {
+  baseUrl?: string,
+}
+
+export const remarkPlugin: Plugin<[PlantUMLPluginParams]> = (options) => {
+  const baseUrl = options.baseUrl ?? 'https://www.plantuml.com/plantuml/svg';
+
+  return plantuml.bind(this)({ baseUrl });
+};

+ 4 - 2
packages/app/src/services/renderer/renderer.tsx

@@ -1,7 +1,6 @@
 // allow only types to import from react
 import { ComponentType } from 'react';
 
-import plantuml from '@akebifiky/remark-simple-plantuml';
 import { Lsx } from '@growi/plugin-lsx/components';
 import * as lsxGrowiPlugin from '@growi/plugin-lsx/services/renderer';
 import growiPlugin from '@growi/remark-growi-plugin';
@@ -34,6 +33,7 @@ import * as keywordHighlighter from './rehype-plugins/keyword-highlighter';
 import { relativeLinks } from './rehype-plugins/relative-links';
 import { relativeLinksByPukiwikiLikeLinker } from './rehype-plugins/relative-links-by-pukiwiki-like-linker';
 import * as toc from './rehype-plugins/relocate-toc';
+import * as plantuml from './remark-plugins/plantuml';
 import { pukiwikiLikeLinker } from './remark-plugins/pukiwiki-like-linker';
 import * as xsvToTable from './remark-plugins/xsv-to-table';
 
@@ -319,7 +319,7 @@ export const generateViewOptions = (
   // add remark plugins
   remarkPlugins.push(
     math,
-    [plantuml, { baseUrl: 'https://www.plantuml.com/plantuml/svg' }],
+    [plantuml.remarkPlugin, { baseUrl: config.plantumlUri }],
     xsvToTable.remarkPlugin,
     lsxGrowiPlugin.remarkPlugin,
   );
@@ -396,6 +396,7 @@ export const generateSimpleViewOptions = (config: RendererConfig, pagePath: stri
   // add remark plugins
   remarkPlugins.push(
     math,
+    [plantuml.remarkPlugin, { baseUrl: config.plantumlUri }],
     xsvToTable.remarkPlugin,
     lsxGrowiPlugin.remarkPlugin,
   );
@@ -431,6 +432,7 @@ export const generatePreviewOptions = (config: RendererConfig, pagePath: string)
   // add remark plugins
   remarkPlugins.push(
     math,
+    [plantuml.remarkPlugin, { baseUrl: config.plantumlUri }],
     xsvToTable.remarkPlugin,
     lsxGrowiPlugin.remarkPlugin,
   );