Skip to content

Commit

Permalink
Merge pull request #7597 from weseek/feat/112904-120355-enable-attach…
Browse files Browse the repository at this point in the history
…ment-refs

feat: Revive attachment-refs with remark
  • Loading branch information
yuki-takei committed Apr 26, 2023
2 parents dde77aa + 68ce6a3 commit de5dce8
Show file tree
Hide file tree
Showing 46 changed files with 1,130 additions and 1,000 deletions.
1 change: 1 addition & 0 deletions apps/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"@google-cloud/storage": "^5.8.5",
"@growi/core": "^6.1.0-RC.0",
"@growi/hackmd": "^6.1.0-RC.0",
"@growi/remark-attachment-refs": "^6.1.0-RC.0",
"@growi/preset-themes": "^6.1.0-RC.0",
"@growi/remark-drawio": "^6.1.0-RC.0",
"@growi/remark-growi-directive": "^6.1.0-RC.0",
Expand Down
26 changes: 26 additions & 0 deletions apps/app/src/client/services/renderer/renderer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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';
// eslint-disable-next-line import/extensions
import * as lsxGrowiPlugin from '@growi/remark-lsx/dist/client/index.mjs';
Expand Down Expand Up @@ -33,6 +34,7 @@ import loggerFactory from '~/utils/logger';
// import EasyGrid from './PreProcessor/EasyGrid';

import '@growi/remark-lsx/dist/client/style.css';
import '@growi/remark-attachment-refs/dist/client/style.css';


const logger = loggerFactory('growi:cli:services:renderer');
Expand All @@ -58,6 +60,7 @@ export const generateViewOptions = (
drawioPlugin.remarkPlugin,
xsvToTable.remarkPlugin,
lsxGrowiPlugin.remarkPlugin,
refsGrowiPlugin.remarkPlugin,
);
if (config.isEnabledLinebreaks) {
remarkPlugins.push(breaks);
Expand All @@ -72,13 +75,15 @@ export const generateViewOptions = (
commonSanitizeOption,
drawioPlugin.sanitizeOption,
lsxGrowiPlugin.sanitizeOption,
refsGrowiPlugin.sanitizeOption,
)]
: () => {};

// add rehype plugins
rehypePlugins.push(
slug,
[lsxGrowiPlugin.rehypePlugin, { pagePath, isSharedPage: config.isSharedPage }],
[refsGrowiPlugin.rehypePlugin, { pagePath }],
rehypeSanitizePlugin,
katex,
[relocateToc.rehypePluginStore, { storeTocNode }],
Expand All @@ -93,6 +98,11 @@ export const generateViewOptions = (
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.drawio = DrawioViewerWithEditButton;
components.table = TableWithEditButton;
}
Expand Down Expand Up @@ -153,6 +163,7 @@ export const generateSimpleViewOptions = (
drawioPlugin.remarkPlugin,
xsvToTable.remarkPlugin,
lsxGrowiPlugin.remarkPlugin,
refsGrowiPlugin.remarkPlugin,
);

const isEnabledLinebreaks = overrideIsEnabledLinebreaks ?? config.isEnabledLinebreaks;
Expand All @@ -171,12 +182,14 @@ export const generateSimpleViewOptions = (
commonSanitizeOption,
drawioPlugin.sanitizeOption,
lsxGrowiPlugin.sanitizeOption,
refsGrowiPlugin.sanitizeOption,
)]
: () => {};

// add rehype plugins
rehypePlugins.push(
[lsxGrowiPlugin.rehypePlugin, { pagePath, isSharedPage: config.isSharedPage }],
[refsGrowiPlugin.rehypePlugin, { pagePath }],
[keywordHighlighter.rehypePlugin, { keywords: highlightKeywords }],
rehypeSanitizePlugin,
katex,
Expand All @@ -185,6 +198,11 @@ 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;
}

Expand Down Expand Up @@ -219,6 +237,7 @@ export const generatePreviewOptions = (config: RendererConfig, pagePath: string)
drawioPlugin.remarkPlugin,
xsvToTable.remarkPlugin,
lsxGrowiPlugin.remarkPlugin,
refsGrowiPlugin.remarkPlugin,
);
if (config.isEnabledLinebreaks) {
remarkPlugins.push(breaks);
Expand All @@ -232,6 +251,7 @@ export const generatePreviewOptions = (config: RendererConfig, pagePath: string)
? [sanitize, deepmerge(
commonSanitizeOption,
lsxGrowiPlugin.sanitizeOption,
refsGrowiPlugin.sanitizeOption,
drawioPlugin.sanitizeOption,
addLineNumberAttribute.sanitizeOption,
)]
Expand All @@ -240,6 +260,7 @@ export const generatePreviewOptions = (config: RendererConfig, pagePath: string)
// add rehype plugins
rehypePlugins.push(
[lsxGrowiPlugin.rehypePlugin, { pagePath, isSharedPage: config.isSharedPage }],
[refsGrowiPlugin.rehypePlugin, { pagePath }],
addLineNumberAttribute.rehypePlugin,
rehypeSanitizePlugin,
katex,
Expand All @@ -248,6 +269,11 @@ 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;
}

Expand Down
2 changes: 2 additions & 0 deletions apps/app/src/server/crowi/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import http from 'http';
import path from 'path';

import { createTerminus } from '@godaddy/terminus';
import attachmentRoutes from '@growi/remark-attachment-refs/dist/server';
import lsxRoutes from '@growi/remark-lsx/dist/server';
import mongoose from 'mongoose';
import next from 'next';
Expand Down Expand Up @@ -531,6 +532,7 @@ Crowi.prototype.setupTerminus = function(server) {

Crowi.prototype.setupRoutesForPlugins = function() {
lsxRoutes(this, this.express);
attachmentRoutes(this, this.express);
};

/**
Expand Down
2 changes: 1 addition & 1 deletion apps/app/src/server/models/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ schema.statics.findByIdsAndViewer = async function(
};

/*
* Find a page by path and viewer. Pass false to useFindOne to use findOne method.
* Find a page by path and viewer. Pass true to useFindOne to use findOne method.
*/
schema.statics.findByPathAndViewer = async function(
path: string | null, user, userGroups = null, useFindOne = false, includeEmpty = false,
Expand Down
39 changes: 0 additions & 39 deletions packages-obsolete/plugin-attachment-refs/package.json

This file was deleted.

10 changes: 0 additions & 10 deletions packages-obsolete/plugin-attachment-refs/src/client-entry.js

This file was deleted.

28 changes: 0 additions & 28 deletions packages-obsolete/plugin-attachment-refs/src/client/css/index.css

This file was deleted.

0 comments on commit de5dce8

Please sign in to comment.