From cf2dc5f03d6b9012ee7fd512494370378bbd23f0 Mon Sep 17 00:00:00 2001 From: Shun Miyazawa Date: Fri, 12 May 2023 17:58:16 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20imprv?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/client/services/renderer/renderer.tsx | 21 +++++++++---------- .../components}/MermaidViewer.tsx | 0 .../mermaid-plugin/components/index.ts | 1 + apps/app/src/features/mermaid-plugin/index.ts | 2 ++ .../features/mermaid-plugin/services/index.ts | 1 + .../mermaid-plugin/services}/mermaid.ts | 0 6 files changed, 14 insertions(+), 11 deletions(-) rename apps/app/src/{components/ReactMarkdownComponents => features/mermaid-plugin/components}/MermaidViewer.tsx (100%) create mode 100644 apps/app/src/features/mermaid-plugin/components/index.ts create mode 100644 apps/app/src/features/mermaid-plugin/index.ts create mode 100644 apps/app/src/features/mermaid-plugin/services/index.ts rename apps/app/src/{services/renderer/remark-plugins => features/mermaid-plugin/services}/mermaid.ts (100%) diff --git a/apps/app/src/client/services/renderer/renderer.tsx b/apps/app/src/client/services/renderer/renderer.tsx index 47f2725d50c..d3883c972d6 100644 --- a/apps/app/src/client/services/renderer/renderer.tsx +++ b/apps/app/src/client/services/renderer/renderer.tsx @@ -17,15 +17,14 @@ import type { Pluggable } from 'unified'; import { DrawioViewerWithEditButton } from '~/components/ReactMarkdownComponents/DrawioViewerWithEditButton'; import { Header } from '~/components/ReactMarkdownComponents/Header'; -import { MermaidViewer } from '~/components/ReactMarkdownComponents/MermaidViewer'; import { TableWithEditButton } from '~/components/ReactMarkdownComponents/TableWithEditButton'; +import * as mermaidPlugin from '~/features/mermaid-plugin'; import { RehypeSanitizeOption } from '~/interfaces/rehype'; import type { RendererOptions } from '~/interfaces/renderer-options'; import type { RendererConfig } from '~/interfaces/services/renderer'; import * as addLineNumberAttribute from '~/services/renderer/rehype-plugins/add-line-number-attribute'; import * as keywordHighlighter from '~/services/renderer/rehype-plugins/keyword-highlighter'; import * as relocateToc from '~/services/renderer/rehype-plugins/relocate-toc'; -import * as mermaid from '~/services/renderer/remark-plugins/mermaid'; import * as plantuml from '~/services/renderer/remark-plugins/plantuml'; import * as xsvToTable from '~/services/renderer/remark-plugins/xsv-to-table'; import { @@ -63,7 +62,7 @@ export const generateViewOptions = ( xsvToTable.remarkPlugin, lsxGrowiPlugin.remarkPlugin, refsGrowiPlugin.remarkPlugin, - mermaid.remarkPlugin, + mermaidPlugin.remarkPlugin, ); if (config.isEnabledLinebreaks) { remarkPlugins.push(breaks); @@ -79,7 +78,7 @@ export const generateViewOptions = ( drawioPlugin.sanitizeOption, lsxGrowiPlugin.sanitizeOption, refsGrowiPlugin.sanitizeOption, - mermaid.sanitizeOption, + mermaidPlugin.sanitizeOption, )] : () => {}; @@ -109,7 +108,7 @@ export const generateViewOptions = ( components.gallery = refsGrowiPlugin.Gallery; components.drawio = DrawioViewerWithEditButton; components.table = TableWithEditButton; - components.mermaid = MermaidViewer; + components.mermaid = mermaidPlugin.MermaidViewer; } if (config.isEnabledXssPrevention) { @@ -169,7 +168,7 @@ export const generateSimpleViewOptions = ( xsvToTable.remarkPlugin, lsxGrowiPlugin.remarkPlugin, refsGrowiPlugin.remarkPlugin, - mermaid.remarkPlugin, + mermaidPlugin.remarkPlugin, ); const isEnabledLinebreaks = overrideIsEnabledLinebreaks ?? config.isEnabledLinebreaks; @@ -189,7 +188,7 @@ export const generateSimpleViewOptions = ( drawioPlugin.sanitizeOption, lsxGrowiPlugin.sanitizeOption, refsGrowiPlugin.sanitizeOption, - mermaid.sanitizeOption, + mermaidPlugin.sanitizeOption, )] : () => {}; @@ -211,7 +210,7 @@ export const generateSimpleViewOptions = ( components.refsimg = refsGrowiPlugin.RefsImgImmutable; components.gallery = refsGrowiPlugin.GalleryImmutable; components.drawio = drawioPlugin.DrawioViewer; - components.mermaid = MermaidViewer; + components.mermaid = mermaidPlugin.MermaidViewer; } if (config.isEnabledXssPrevention) { @@ -246,7 +245,7 @@ export const generatePreviewOptions = (config: RendererConfig, pagePath: string) xsvToTable.remarkPlugin, lsxGrowiPlugin.remarkPlugin, refsGrowiPlugin.remarkPlugin, - mermaid.remarkPlugin, + mermaidPlugin.remarkPlugin, ); if (config.isEnabledLinebreaks) { remarkPlugins.push(breaks); @@ -263,7 +262,7 @@ export const generatePreviewOptions = (config: RendererConfig, pagePath: string) refsGrowiPlugin.sanitizeOption, drawioPlugin.sanitizeOption, addLineNumberAttribute.sanitizeOption, - mermaid.sanitizeOption, + mermaidPlugin.sanitizeOption, )] : () => {}; @@ -285,7 +284,7 @@ export const generatePreviewOptions = (config: RendererConfig, pagePath: string) components.refsimg = refsGrowiPlugin.RefsImgImmutable; components.gallery = refsGrowiPlugin.GalleryImmutable; components.drawio = drawioPlugin.DrawioViewer; - components.mermaid = MermaidViewer; + components.mermaid = mermaidPlugin.MermaidViewer; } if (config.isEnabledXssPrevention) { diff --git a/apps/app/src/components/ReactMarkdownComponents/MermaidViewer.tsx b/apps/app/src/features/mermaid-plugin/components/MermaidViewer.tsx similarity index 100% rename from apps/app/src/components/ReactMarkdownComponents/MermaidViewer.tsx rename to apps/app/src/features/mermaid-plugin/components/MermaidViewer.tsx diff --git a/apps/app/src/features/mermaid-plugin/components/index.ts b/apps/app/src/features/mermaid-plugin/components/index.ts new file mode 100644 index 00000000000..3e6cb3e4164 --- /dev/null +++ b/apps/app/src/features/mermaid-plugin/components/index.ts @@ -0,0 +1 @@ +export { MermaidViewer } from './MermaidViewer'; diff --git a/apps/app/src/features/mermaid-plugin/index.ts b/apps/app/src/features/mermaid-plugin/index.ts new file mode 100644 index 00000000000..80e3bea6755 --- /dev/null +++ b/apps/app/src/features/mermaid-plugin/index.ts @@ -0,0 +1,2 @@ +export * from './components'; +export * from './services'; diff --git a/apps/app/src/features/mermaid-plugin/services/index.ts b/apps/app/src/features/mermaid-plugin/services/index.ts new file mode 100644 index 00000000000..f354bf323ed --- /dev/null +++ b/apps/app/src/features/mermaid-plugin/services/index.ts @@ -0,0 +1 @@ +export { remarkPlugin, sanitizeOption } from './mermaid'; diff --git a/apps/app/src/services/renderer/remark-plugins/mermaid.ts b/apps/app/src/features/mermaid-plugin/services/mermaid.ts similarity index 100% rename from apps/app/src/services/renderer/remark-plugins/mermaid.ts rename to apps/app/src/features/mermaid-plugin/services/mermaid.ts