File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { Text , Link , Code , TextProps } from '@chakra-ui/react' ;
22import { themeColor } from '~/other/types' ;
3- import DOMPurify from 'dompurify' ;
3+ import createDOMPurify from 'dompurify' ;
44import React from 'react' ;
55import katex from 'katex' ;
66
77export type TextParserProps = {
88 children : string | string [ ] ;
99} & TextProps ;
1010
11+ const DOMPurify = typeof window !== 'undefined' ? createDOMPurify ( window ) : null ;
12+
1113export 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}
You can’t perform that action at this time.
0 commit comments