|
|
@@ -1,10 +1,10 @@
|
|
|
import assert from 'assert';
|
|
|
|
|
|
import { isClient } from '@growi/core/dist/utils/browser-utils';
|
|
|
-import * as refsGrowiPlugin from '@growi/remark-attachment-refs/dist/client/index.mjs';
|
|
|
-import * as drawioPlugin from '@growi/remark-drawio';
|
|
|
+import * as refsGrowiDirective from '@growi/remark-attachment-refs/dist/client/index.mjs';
|
|
|
+import * as drawio from '@growi/remark-drawio';
|
|
|
// eslint-disable-next-line import/extensions
|
|
|
-import * as lsxGrowiPlugin from '@growi/remark-lsx/dist/client/index.mjs';
|
|
|
+import * as lsxGrowiDirective from '@growi/remark-lsx/dist/client/index.mjs';
|
|
|
import katex from 'rehype-katex';
|
|
|
import sanitize from 'rehype-sanitize';
|
|
|
import slug from 'rehype-slug';
|
|
|
@@ -14,17 +14,18 @@ import math from 'remark-math';
|
|
|
import deepmerge from 'ts-deepmerge';
|
|
|
import type { Pluggable } from 'unified';
|
|
|
|
|
|
-
|
|
|
import { DrawioViewerWithEditButton } from '~/components/ReactMarkdownComponents/DrawioViewerWithEditButton';
|
|
|
import { Header } from '~/components/ReactMarkdownComponents/Header';
|
|
|
+import { RichAttachment } from '~/components/ReactMarkdownComponents/RichAttachment';
|
|
|
import { TableWithEditButton } from '~/components/ReactMarkdownComponents/TableWithEditButton';
|
|
|
-import * as mermaidPlugin from '~/features/mermaid-plugin';
|
|
|
+import * as mermaid from '~/features/mermaid';
|
|
|
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 attachment from '~/services/renderer/remark-plugins/attachment';
|
|
|
import * as plantuml from '~/services/renderer/remark-plugins/plantuml';
|
|
|
import * as xsvToTable from '~/services/renderer/remark-plugins/xsv-to-table';
|
|
|
import {
|
|
|
@@ -58,11 +59,12 @@ export const generateViewOptions = (
|
|
|
remarkPlugins.push(
|
|
|
math,
|
|
|
[plantuml.remarkPlugin, { plantumlUri: config.plantumlUri }],
|
|
|
- drawioPlugin.remarkPlugin,
|
|
|
+ drawio.remarkPlugin,
|
|
|
+ mermaid.remarkPlugin,
|
|
|
xsvToTable.remarkPlugin,
|
|
|
- lsxGrowiPlugin.remarkPlugin,
|
|
|
- refsGrowiPlugin.remarkPlugin,
|
|
|
- mermaidPlugin.remarkPlugin,
|
|
|
+ attachment.remarkPlugin,
|
|
|
+ lsxGrowiDirective.remarkPlugin,
|
|
|
+ refsGrowiDirective.remarkPlugin,
|
|
|
);
|
|
|
if (config.isEnabledLinebreaks) {
|
|
|
remarkPlugins.push(breaks);
|
|
|
@@ -75,18 +77,19 @@ export const generateViewOptions = (
|
|
|
const rehypeSanitizePlugin: Pluggable<any[]> | (() => void) = config.isEnabledXssPrevention
|
|
|
? [sanitize, deepmerge(
|
|
|
commonSanitizeOption,
|
|
|
- drawioPlugin.sanitizeOption,
|
|
|
- lsxGrowiPlugin.sanitizeOption,
|
|
|
- refsGrowiPlugin.sanitizeOption,
|
|
|
- mermaidPlugin.sanitizeOption,
|
|
|
+ drawio.sanitizeOption,
|
|
|
+ mermaid.sanitizeOption,
|
|
|
+ attachment.sanitizeOption,
|
|
|
+ lsxGrowiDirective.sanitizeOption,
|
|
|
+ refsGrowiDirective.sanitizeOption,
|
|
|
)]
|
|
|
: () => {};
|
|
|
|
|
|
// add rehype plugins
|
|
|
rehypePlugins.push(
|
|
|
slug,
|
|
|
- [lsxGrowiPlugin.rehypePlugin, { pagePath, isSharedPage: config.isSharedPage }],
|
|
|
- [refsGrowiPlugin.rehypePlugin, { pagePath }],
|
|
|
+ [lsxGrowiDirective.rehypePlugin, { pagePath, isSharedPage: config.isSharedPage }],
|
|
|
+ [refsGrowiDirective.rehypePlugin, { pagePath }],
|
|
|
rehypeSanitizePlugin,
|
|
|
katex,
|
|
|
[relocateToc.rehypePluginStore, { storeTocNode }],
|
|
|
@@ -100,15 +103,16 @@ export const generateViewOptions = (
|
|
|
components.h4 = Header;
|
|
|
components.h5 = Header;
|
|
|
components.h6 = Header;
|
|
|
- components.lsx = lsxGrowiPlugin.Lsx;
|
|
|
- components.ref = refsGrowiPlugin.Ref;
|
|
|
- components.refs = refsGrowiPlugin.Refs;
|
|
|
- components.refimg = refsGrowiPlugin.RefImg;
|
|
|
- components.refsimg = refsGrowiPlugin.RefsImg;
|
|
|
- components.gallery = refsGrowiPlugin.Gallery;
|
|
|
+ components.lsx = lsxGrowiDirective.Lsx;
|
|
|
+ components.ref = refsGrowiDirective.Ref;
|
|
|
+ components.refs = refsGrowiDirective.Refs;
|
|
|
+ components.refimg = refsGrowiDirective.RefImg;
|
|
|
+ components.refsimg = refsGrowiDirective.RefsImg;
|
|
|
+ components.gallery = refsGrowiDirective.Gallery;
|
|
|
components.drawio = DrawioViewerWithEditButton;
|
|
|
components.table = TableWithEditButton;
|
|
|
- components.mermaid = mermaidPlugin.MermaidViewer;
|
|
|
+ components.mermaid = mermaid.MermaidViewer;
|
|
|
+ components.attachment = RichAttachment;
|
|
|
}
|
|
|
|
|
|
if (config.isEnabledXssPrevention) {
|
|
|
@@ -164,11 +168,12 @@ export const generateSimpleViewOptions = (
|
|
|
remarkPlugins.push(
|
|
|
math,
|
|
|
[plantuml.remarkPlugin, { plantumlUri: config.plantumlUri }],
|
|
|
- drawioPlugin.remarkPlugin,
|
|
|
+ drawio.remarkPlugin,
|
|
|
+ mermaid.remarkPlugin,
|
|
|
xsvToTable.remarkPlugin,
|
|
|
- lsxGrowiPlugin.remarkPlugin,
|
|
|
- refsGrowiPlugin.remarkPlugin,
|
|
|
- mermaidPlugin.remarkPlugin,
|
|
|
+ attachment.remarkPlugin,
|
|
|
+ lsxGrowiDirective.remarkPlugin,
|
|
|
+ refsGrowiDirective.remarkPlugin,
|
|
|
);
|
|
|
|
|
|
const isEnabledLinebreaks = overrideIsEnabledLinebreaks ?? config.isEnabledLinebreaks;
|
|
|
@@ -185,17 +190,18 @@ export const generateSimpleViewOptions = (
|
|
|
const rehypeSanitizePlugin: Pluggable<any[]> | (() => void) = config.isEnabledXssPrevention
|
|
|
? [sanitize, deepmerge(
|
|
|
commonSanitizeOption,
|
|
|
- drawioPlugin.sanitizeOption,
|
|
|
- lsxGrowiPlugin.sanitizeOption,
|
|
|
- refsGrowiPlugin.sanitizeOption,
|
|
|
- mermaidPlugin.sanitizeOption,
|
|
|
+ drawio.sanitizeOption,
|
|
|
+ mermaid.sanitizeOption,
|
|
|
+ attachment.sanitizeOption,
|
|
|
+ lsxGrowiDirective.sanitizeOption,
|
|
|
+ refsGrowiDirective.sanitizeOption,
|
|
|
)]
|
|
|
: () => {};
|
|
|
|
|
|
// add rehype plugins
|
|
|
rehypePlugins.push(
|
|
|
- [lsxGrowiPlugin.rehypePlugin, { pagePath, isSharedPage: config.isSharedPage }],
|
|
|
- [refsGrowiPlugin.rehypePlugin, { pagePath }],
|
|
|
+ [lsxGrowiDirective.rehypePlugin, { pagePath, isSharedPage: config.isSharedPage }],
|
|
|
+ [refsGrowiDirective.rehypePlugin, { pagePath }],
|
|
|
[keywordHighlighter.rehypePlugin, { keywords: highlightKeywords }],
|
|
|
rehypeSanitizePlugin,
|
|
|
katex,
|
|
|
@@ -203,14 +209,15 @@ export const generateSimpleViewOptions = (
|
|
|
|
|
|
// add components
|
|
|
if (components != null) {
|
|
|
- components.lsx = lsxGrowiPlugin.LsxImmutable;
|
|
|
- components.ref = refsGrowiPlugin.RefImmutable;
|
|
|
- components.refs = refsGrowiPlugin.RefsImmutable;
|
|
|
- components.refimg = refsGrowiPlugin.RefImgImmutable;
|
|
|
- components.refsimg = refsGrowiPlugin.RefsImgImmutable;
|
|
|
- components.gallery = refsGrowiPlugin.GalleryImmutable;
|
|
|
- components.drawio = drawioPlugin.DrawioViewer;
|
|
|
- components.mermaid = mermaidPlugin.MermaidViewer;
|
|
|
+ components.lsx = lsxGrowiDirective.LsxImmutable;
|
|
|
+ components.ref = refsGrowiDirective.RefImmutable;
|
|
|
+ components.refs = refsGrowiDirective.RefsImmutable;
|
|
|
+ components.refimg = refsGrowiDirective.RefImgImmutable;
|
|
|
+ components.refsimg = refsGrowiDirective.RefsImgImmutable;
|
|
|
+ components.gallery = refsGrowiDirective.GalleryImmutable;
|
|
|
+ components.drawio = drawio.DrawioViewer;
|
|
|
+ components.mermaid = mermaid.MermaidViewer;
|
|
|
+ components.attachment = RichAttachment;
|
|
|
}
|
|
|
|
|
|
if (config.isEnabledXssPrevention) {
|
|
|
@@ -241,11 +248,12 @@ export const generatePreviewOptions = (config: RendererConfig, pagePath: string)
|
|
|
remarkPlugins.push(
|
|
|
math,
|
|
|
[plantuml.remarkPlugin, { plantumlUri: config.plantumlUri }],
|
|
|
- drawioPlugin.remarkPlugin,
|
|
|
+ drawio.remarkPlugin,
|
|
|
+ mermaid.remarkPlugin,
|
|
|
xsvToTable.remarkPlugin,
|
|
|
- lsxGrowiPlugin.remarkPlugin,
|
|
|
- refsGrowiPlugin.remarkPlugin,
|
|
|
- mermaidPlugin.remarkPlugin,
|
|
|
+ attachment.remarkPlugin,
|
|
|
+ lsxGrowiDirective.remarkPlugin,
|
|
|
+ refsGrowiDirective.remarkPlugin,
|
|
|
);
|
|
|
if (config.isEnabledLinebreaks) {
|
|
|
remarkPlugins.push(breaks);
|
|
|
@@ -258,18 +266,19 @@ export const generatePreviewOptions = (config: RendererConfig, pagePath: string)
|
|
|
const rehypeSanitizePlugin: Pluggable<any[]> | (() => void) = config.isEnabledXssPrevention
|
|
|
? [sanitize, deepmerge(
|
|
|
commonSanitizeOption,
|
|
|
- lsxGrowiPlugin.sanitizeOption,
|
|
|
- refsGrowiPlugin.sanitizeOption,
|
|
|
- drawioPlugin.sanitizeOption,
|
|
|
+ drawio.sanitizeOption,
|
|
|
+ mermaid.sanitizeOption,
|
|
|
+ attachment.sanitizeOption,
|
|
|
+ lsxGrowiDirective.sanitizeOption,
|
|
|
+ refsGrowiDirective.sanitizeOption,
|
|
|
addLineNumberAttribute.sanitizeOption,
|
|
|
- mermaidPlugin.sanitizeOption,
|
|
|
)]
|
|
|
: () => {};
|
|
|
|
|
|
// add rehype plugins
|
|
|
rehypePlugins.push(
|
|
|
- [lsxGrowiPlugin.rehypePlugin, { pagePath, isSharedPage: config.isSharedPage }],
|
|
|
- [refsGrowiPlugin.rehypePlugin, { pagePath }],
|
|
|
+ [lsxGrowiDirective.rehypePlugin, { pagePath, isSharedPage: config.isSharedPage }],
|
|
|
+ [refsGrowiDirective.rehypePlugin, { pagePath }],
|
|
|
addLineNumberAttribute.rehypePlugin,
|
|
|
rehypeSanitizePlugin,
|
|
|
katex,
|
|
|
@@ -277,14 +286,15 @@ export const generatePreviewOptions = (config: RendererConfig, pagePath: string)
|
|
|
|
|
|
// add components
|
|
|
if (components != null) {
|
|
|
- components.lsx = lsxGrowiPlugin.LsxImmutable;
|
|
|
- components.ref = refsGrowiPlugin.RefImmutable;
|
|
|
- components.refs = refsGrowiPlugin.RefsImmutable;
|
|
|
- components.refimg = refsGrowiPlugin.RefImgImmutable;
|
|
|
- components.refsimg = refsGrowiPlugin.RefsImgImmutable;
|
|
|
- components.gallery = refsGrowiPlugin.GalleryImmutable;
|
|
|
- components.drawio = drawioPlugin.DrawioViewer;
|
|
|
- components.mermaid = mermaidPlugin.MermaidViewer;
|
|
|
+ components.lsx = lsxGrowiDirective.LsxImmutable;
|
|
|
+ components.ref = refsGrowiDirective.RefImmutable;
|
|
|
+ components.refs = refsGrowiDirective.RefsImmutable;
|
|
|
+ components.refimg = refsGrowiDirective.RefImgImmutable;
|
|
|
+ components.refsimg = refsGrowiDirective.RefsImgImmutable;
|
|
|
+ components.gallery = refsGrowiDirective.GalleryImmutable;
|
|
|
+ components.drawio = drawio.DrawioViewer;
|
|
|
+ components.mermaid = mermaid.MermaidViewer;
|
|
|
+ components.attachment = RichAttachment;
|
|
|
}
|
|
|
|
|
|
if (config.isEnabledXssPrevention) {
|