2024-05-31 19:49:46 +05:30
|
|
|
import React from 'react';
|
|
|
|
|
import parse, { HTMLReactParserOptions } from 'html-react-parser';
|
|
|
|
|
import Linkify from 'linkify-react';
|
2024-07-30 17:48:59 +05:30
|
|
|
import { Opts } from 'linkifyjs';
|
2024-05-31 19:49:46 +05:30
|
|
|
import { MessageEmptyContent } from './content';
|
|
|
|
|
import { sanitizeCustomHtml } from '../../utils/sanitize';
|
2024-07-30 17:48:59 +05:30
|
|
|
import { highlightText, scaleSystemEmoji } from '../../plugins/react-custom-html-parser';
|
2024-05-31 19:49:46 +05:30
|
|
|
|
|
|
|
|
type RenderBodyProps = {
|
|
|
|
|
body: string;
|
|
|
|
|
customBody?: string;
|
|
|
|
|
|
|
|
|
|
highlightRegex?: RegExp;
|
|
|
|
|
htmlReactParserOptions: HTMLReactParserOptions;
|
2024-07-30 17:48:59 +05:30
|
|
|
linkifyOpts: Opts;
|
2024-05-31 19:49:46 +05:30
|
|
|
};
|
|
|
|
|
export function RenderBody({
|
|
|
|
|
body,
|
|
|
|
|
customBody,
|
|
|
|
|
highlightRegex,
|
|
|
|
|
htmlReactParserOptions,
|
2024-07-30 17:48:59 +05:30
|
|
|
linkifyOpts,
|
2024-05-31 19:49:46 +05:30
|
|
|
}: RenderBodyProps) {
|
|
|
|
|
if (body === '') <MessageEmptyContent />;
|
|
|
|
|
if (customBody) {
|
|
|
|
|
if (customBody === '') <MessageEmptyContent />;
|
|
|
|
|
return parse(sanitizeCustomHtml(customBody), htmlReactParserOptions);
|
|
|
|
|
}
|
|
|
|
|
return (
|
2024-07-30 17:48:59 +05:30
|
|
|
<Linkify options={linkifyOpts}>
|
2024-05-31 19:49:46 +05:30
|
|
|
{highlightRegex
|
|
|
|
|
? highlightText(highlightRegex, scaleSystemEmoji(body))
|
|
|
|
|
: scaleSystemEmoji(body)}
|
|
|
|
|
</Linkify>
|
|
|
|
|
);
|
|
|
|
|
}
|