Skip to content

Commit 9662649

Browse files
committed
fix: update DOMPurify import and ensure safe HTML rendering in TextParser
1 parent 647f339 commit 9662649

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

app/components/TextParser.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
import { Text, Link, Code, TextProps } from '@chakra-ui/react';
22
import { themeColor } from '~/other/types';
3-
import DOMPurify from 'dompurify';
3+
import createDOMPurify from 'dompurify';
44
import React from 'react';
55
import katex from 'katex';
66

77
export type TextParserProps = {
88
children: string | string[];
99
} & TextProps;
1010

11+
const DOMPurify = typeof window !== 'undefined' ? createDOMPurify(window) : null;
12+
1113
export function TextParser({ children, ...props }: TextParserProps) {
1214
const content = Array.isArray(children) ? children.join('\n\n') : children;
1315

1416
const renderMath = (expr: string) => {
1517
const html = katex.renderToString(expr, { throwOnError: false, strict: false });
16-
const safeHtml = DOMPurify.sanitize(html);
18+
const safeHtml = DOMPurify ? DOMPurify.sanitize(html) : html;
1719

1820
return (
1921
<Text
@@ -102,5 +104,5 @@ export function TextParser({ children, ...props }: TextParserProps) {
102104
});
103105
};
104106

105-
return <>{parseInline(content)}</>;
107+
return <>{parseInline(content).flat(Infinity)}</>;
106108
}

0 commit comments

Comments
 (0)