-
Notifications
You must be signed in to change notification settings - Fork 527
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extracts markdown rendering out of ChatMessageBox.tsx (#757)
- Loading branch information
Showing
3 changed files
with
45 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <Twemoji text={props.children} />; | ||
}, | ||
image: (props: any) => { | ||
// TODO: fix scroll behavior after image loads | ||
return ( | ||
<img | ||
alt={props.alt || ''} | ||
src={props.src} | ||
{...props} | ||
style={{maxWidth: '100%', maxHeight: 400}} | ||
/> | ||
); | ||
}, | ||
}; | ||
|
||
type Props = { | ||
className?: string; | ||
source: string; | ||
}; | ||
|
||
const MarkdownRenderer = ({className, source}: Props) => { | ||
return ( | ||
<ReactMarkdown | ||
className={`Text--markdown ${className}`} | ||
source={source} | ||
allowedTypes={allowedNodeTypes} | ||
renderers={renderers} | ||
plugins={[breaks]} | ||
/> | ||
); | ||
}; | ||
|
||
export default MarkdownRenderer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters