From 25efe9db51b860730104e4a480c85c98212bff43 Mon Sep 17 00:00:00 2001 From: Yuki Takei Date: Mon, 21 Oct 2024 09:45:33 +0000 Subject: [PATCH] Add codeBlock.sanitizeOption to the common sanitize option so that CodeBlock is rendered when SSR --- apps/app/src/services/renderer/renderer.tsx | 26 +++++++++++---------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/apps/app/src/services/renderer/renderer.tsx b/apps/app/src/services/renderer/renderer.tsx index b78494b15e6..8072d6b960e 100644 --- a/apps/app/src/services/renderer/renderer.tsx +++ b/apps/app/src/services/renderer/renderer.tsx @@ -44,15 +44,18 @@ let commonSanitizeOption: SanitizeOption; export const getCommonSanitizeOption = (config:RendererConfig): SanitizeOption => { if (commonSanitizeOption == null || config.sanitizeType !== currentInitializedSanitizeType) { // initialize - commonSanitizeOption = { - tagNames: config.sanitizeType === RehypeSanitizeType.RECOMMENDED - ? recommendedTagNames - : config.customTagWhitelist ?? recommendedTagNames, - attributes: config.sanitizeType === RehypeSanitizeType.RECOMMENDED - ? recommendedAttributes - : config.customAttrWhitelist ?? recommendedAttributes, - clobberPrefix: '', // remove clobber prefix - }; + commonSanitizeOption = deepmerge( + { + tagNames: config.sanitizeType === RehypeSanitizeType.RECOMMENDED + ? recommendedTagNames + : config.customTagWhitelist ?? recommendedTagNames, + attributes: config.sanitizeType === RehypeSanitizeType.RECOMMENDED + ? recommendedAttributes + : config.customAttrWhitelist ?? recommendedAttributes, + clobberPrefix: '', // remove clobber prefix + }, + codeBlock.sanitizeOption, + ); currentInitializedSanitizeType = config.sanitizeType; } @@ -123,6 +126,7 @@ export const generateSSRViewOptions = ( config: RendererConfig, pagePath: string, ): RendererOptions => { + const options = generateCommonOptions(pagePath); const { remarkPlugins, rehypePlugins } = options; @@ -140,9 +144,7 @@ export const generateSSRViewOptions = ( } const rehypeSanitizePlugin: Pluggable | (() => void) = config.isEnabledXssPrevention - ? [sanitize, deepmerge( - getCommonSanitizeOption(config), - )] + ? [sanitize, getCommonSanitizeOption(config)] : () => {}; // add rehype plugins