diff --git a/assets/src/components/MarkdownRenderer.tsx b/assets/src/components/MarkdownRenderer.tsx new file mode 100644 index 000000000..9a804ab04 --- /dev/null +++ b/assets/src/components/MarkdownRenderer.tsx @@ -0,0 +1,41 @@ +import React from 'react'; +import ReactMarkdown from 'react-markdown'; +import breaks from 'remark-breaks'; +import {Twemoji} from 'react-emoji-render'; +import {allowedNodeTypes} from './common'; + +const renderers = { + text: (props: any) => { + return ; + }, + image: (props: any) => { + // TODO: fix scroll behavior after image loads + return ( + {props.alt + ); + }, +}; + +type Props = { + className?: string; + source: string; +}; + +const MarkdownRenderer = ({className, source}: Props) => { + return ( + + ); +}; + +export default MarkdownRenderer; diff --git a/assets/src/components/common.tsx b/assets/src/components/common.tsx index eb41f7a12..3344047c0 100644 --- a/assets/src/components/common.tsx +++ b/assets/src/components/common.tsx @@ -39,6 +39,7 @@ import { } from '@ant-design/colors'; import DatePicker from './DatePicker'; +import MarkdownRenderer from './MarkdownRenderer'; export type {UploadChangeParam} from 'antd/lib/upload'; export type {UploadFile} from 'antd/lib/upload/interface'; @@ -122,6 +123,7 @@ export { Dropdown, Empty, Input, + MarkdownRenderer, Menu, Modal, notification, diff --git a/assets/src/components/conversations/ChatMessageBox.tsx b/assets/src/components/conversations/ChatMessageBox.tsx index 2594f678b..4d41dbd41 100644 --- a/assets/src/components/conversations/ChatMessageBox.tsx +++ b/assets/src/components/conversations/ChatMessageBox.tsx @@ -1,29 +1,9 @@ import React from 'react'; -import ReactMarkdown from 'react-markdown'; -import breaks from 'remark-breaks'; -import {Twemoji} from 'react-emoji-render'; import {Box} from 'theme-ui'; -import {allowedNodeTypes} from '../common'; +import {MarkdownRenderer} from '../common'; import {Attachment} from '../../types'; import {PaperClipOutlined} from '../icons'; -const renderers = { - text: (props: any) => { - return ; - }, - image: (props: any) => { - // TODO: fix scroll behavior after image loads - return ( - {props.alt - ); - }, -}; - const ChatMessageAttachment = ({ attachment, color, @@ -78,13 +58,7 @@ const ChatMessageBox = ({ return ( - + {attachments && attachments.length > 0 && (