Is markdown enabled on stream-chat-react?
We use stream-chat for both react app and react-native, and we have special messages send as markdown strings from the server side. The markdown is rendered as expected on react-native, but we could not find a way to customize or enable the markdown on the react app. We also did not find any references or guide on how to do that with the react library.
So our questions are: Is markdown supported on stream-chat-react? If it is supported, can you show an example on how to enable and customize it? Or we have to override the message component and add a markdown component to do the rendering.
Thanks!
gz#8959
Hello, on the React side we use the react-markdown library (https://github.com/remarkjs/react-markdown). These are the types we currently allow, and do not enable ones that could potentially harm the UI, like image or heading...
const allowedMarkups = [
'html',
'root',
'text',
'break',
'paragraph',
'emphasis',
'strong',
'link',
'list',
'listItem',
'code',
'inlineCode',
'blockquote',
'delete',
];
The allowed types are then passed into the ReactMarkdown component...
<ReactMarkdown
allowedTypes={allowedMarkups}
source={newText}
renderers={markDownRenderers}
escapeHtml={true}
unwrapDisallowed={true}
transformLinkUri={(uri) =>
uri.startsWith('app://') ? uri : RootReactMarkdown.uriTransformer(uri)
}
/>
This component is returned out of our renderText function in our utils file which sets the text for our default message UI components. These types cannot be customized to prevent any unintended circumstances within our defaults. So if you need to enable additional types, you can create a custom message UI component (supplied as the Message prop on MessageList).
Closing as I believe this answers the questions and there isn't anything else to add, but of course let us know if we can be of further help. Thanks!