Skip to content

Commit

Permalink
Add codeBlock.sanitizeOption to the common sanitize option so that Co…
Browse files Browse the repository at this point in the history
…deBlock is rendered when SSR
  • Loading branch information
yuki-takei committed Oct 21, 2024
1 parent df32f67 commit 25efe9d
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions apps/app/src/services/renderer/renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -123,6 +126,7 @@ export const generateSSRViewOptions = (
config: RendererConfig,
pagePath: string,
): RendererOptions => {

const options = generateCommonOptions(pagePath);

const { remarkPlugins, rehypePlugins } = options;
Expand All @@ -140,9 +144,7 @@ export const generateSSRViewOptions = (
}

const rehypeSanitizePlugin: Pluggable | (() => void) = config.isEnabledXssPrevention
? [sanitize, deepmerge(
getCommonSanitizeOption(config),
)]
? [sanitize, getCommonSanitizeOption(config)]
: () => {};

// add rehype plugins
Expand Down

0 comments on commit 25efe9d

Please sign in to comment.