From 3dcc9899103ae7cc4308f179119a7a3660890b9a Mon Sep 17 00:00:00 2001 From: atsuki-t Date: Wed, 11 Oct 2023 16:27:10 +0000 Subject: [PATCH] use markdown-it --- apps/app/src/server/routes/cms.ts | 39 ++++--------------------------- 1 file changed, 4 insertions(+), 35 deletions(-) diff --git a/apps/app/src/server/routes/cms.ts b/apps/app/src/server/routes/cms.ts index 3c7c8ddaed..fb120f6a2c 100644 --- a/apps/app/src/server/routes/cms.ts +++ b/apps/app/src/server/routes/cms.ts @@ -1,9 +1,6 @@ -import remarkParse from 'remark-parse'; -import remarkRehype from 'remark-rehype'; -import remarkStringify from 'remark-stringify'; -import { unified } from 'unified'; +import md from 'markdown-it'; +import emoji from 'markdown-it-emoji'; -import { generateCmsRenderingOptions } from '~/services/renderer/cms_renderer'; import loggerFactory from '~/utils/logger'; const logger = loggerFactory('growi:routes:cms:pages'); @@ -16,26 +13,6 @@ module.exports = function(crowi) { actions.api = api; - const { configManager } = crowi; - - const rendererConfig = { - isEnabledLinebreaks: configManager.getConfig('markdown', 'markdown:isEnabledLinebreaks'), - isEnabledLinebreaksInComments: configManager.getConfig('markdown', 'markdown:isEnabledLinebreaksInComments'), - isEnabledMarp: configManager.getConfig('crowi', 'customize:isEnabledMarp'), - adminPreferredIndentSize: configManager.getConfig('markdown', 'markdown:adminPreferredIndentSize'), - isIndentSizeForced: configManager.getConfig('markdown', 'markdown:isIndentSizeForced'), - - drawioUri: configManager.getConfig('crowi', 'app:drawioUri'), - plantumlUri: configManager.getConfig('crowi', 'app:plantumlUri'), - - // XSS Options - isEnabledXssPrevention: configManager.getConfig('markdown', 'markdown:rehypeSanitize:isEnabledPrevention'), - xssOption: configManager.getConfig('markdown', 'markdown:rehypeSanitize:option'), - attrWhitelist: JSON.parse(crowi.configManager.getConfig('markdown', 'markdown:rehypeSanitize:attributes')), - tagWhitelist: crowi.configManager.getConfig('markdown', 'markdown:rehypeSanitize:tagNames'), - highlightJsStyleBorder: crowi.configManager.getConfig('crowi', 'customize:highlightJsStyleBorder'), - }; - /** * @api {get} /pages.get get pages * @apiName get @@ -73,17 +50,9 @@ module.exports = function(crowi) { } } - const rendererOptions = generateCmsRenderingOptions(rendererConfig, pageId); - - const htmlString = await unified() - .use(remarkParse) - .use(rendererOptions.remarkPlugins) - .use(remarkRehype) - .use(rendererOptions.rehypePlugins) - .use(remarkStringify) - .process(page.revision.body); + const htmlString = md({ html: true }).use(emoji).render(page.revision.body); - return res.apiv3({ ...page, htlm: htmlString }); + return res.apiv3({ ...page, htmlString }); }; return actions;