Skip to content

Commit c15a1a7

Browse files
committed
feat: markdown渲染的图片允许被放大预览
顺便升级了一下markdown渲染组件的版本
1 parent 94fcbb7 commit c15a1a7

File tree

3 files changed

+396
-47
lines changed

3 files changed

+396
-47
lines changed

client/web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"react-easy-crop": "^3.5.3",
5454
"react-helmet": "^6.1.0",
5555
"react-is": "^18.2.0",
56-
"react-markdown": "^6.0.3",
56+
"react-markdown": "^8.0.4",
5757
"react-mentions": "^4.4.7",
5858
"react-router": "^6.5.0",
5959
"react-router-dom": "^6.5.0",

client/web/src/components/Markdown.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { markAbsoluteUrl } from '@/utils/url-helper';
2-
import React, { useCallback } from 'react';
2+
import React, { useCallback, useMemo } from 'react';
33
import { isValidStr } from 'tailchat-shared';
44
import { Loadable } from './Loadable';
5+
import { Image } from 'tailchat-design';
56
import './Markdown.less';
67

78
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -23,12 +24,25 @@ export const Markdown: React.FC<{
2324
[baseUrl]
2425
);
2526

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+
2639
return (
2740
<ReactMarkdown
2841
className="tailchat-markdown"
2942
transformImageUri={(src) => transformUrl(src)}
3043
transformLinkUri={(href) => transformUrl(href)}
3144
skipHtml={true}
45+
components={components}
3246
>
3347
{raw}
3448
</ReactMarkdown>

0 commit comments

Comments
 (0)