File tree Expand file tree Collapse file tree 3 files changed +396
-47
lines changed Expand file tree Collapse file tree 3 files changed +396
-47
lines changed Original file line number Diff line number Diff line change 53
53
"react-easy-crop" : " ^3.5.3" ,
54
54
"react-helmet" : " ^6.1.0" ,
55
55
"react-is" : " ^18.2.0" ,
56
- "react-markdown" : " ^6 .0.3 " ,
56
+ "react-markdown" : " ^8 .0.4 " ,
57
57
"react-mentions" : " ^4.4.7" ,
58
58
"react-router" : " ^6.5.0" ,
59
59
"react-router-dom" : " ^6.5.0" ,
Original file line number Diff line number Diff line change 1
1
import { markAbsoluteUrl } from '@/utils/url-helper' ;
2
- import React , { useCallback } from 'react' ;
2
+ import React , { useCallback , useMemo } from 'react' ;
3
3
import { isValidStr } from 'tailchat-shared' ;
4
4
import { Loadable } from './Loadable' ;
5
+ import { Image } from 'tailchat-design' ;
5
6
import './Markdown.less' ;
6
7
7
8
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -23,12 +24,25 @@ export const Markdown: React.FC<{
23
24
[ baseUrl ]
24
25
) ;
25
26
27
+ /**
28
+ * Markdown自定义渲染组件
29
+ */
30
+ const components = useMemo <
31
+ React . ComponentProps < typeof ReactMarkdown > [ 'components' ]
32
+ > (
33
+ ( ) => ( {
34
+ img : ( props ) => < Image src = { props . src } preview = { true } /> ,
35
+ } ) ,
36
+ [ ]
37
+ ) ;
38
+
26
39
return (
27
40
< ReactMarkdown
28
41
className = "tailchat-markdown"
29
42
transformImageUri = { ( src ) => transformUrl ( src ) }
30
43
transformLinkUri = { ( href ) => transformUrl ( href ) }
31
44
skipHtml = { true }
45
+ components = { components }
32
46
>
33
47
{ raw }
34
48
</ ReactMarkdown >
You can’t perform that action at this time.
0 commit comments