2021-10-20 16:32:58 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { MarkdownAST } from '@rocket.chat/message-parser';
|
2022-02-17 15:27:01 +00:00
|
|
|
import isEmpty from 'lodash/isEmpty';
|
2021-10-20 16:32:58 +00:00
|
|
|
|
|
|
|
import Quote from './Quote';
|
|
|
|
import Paragraph from './Paragraph';
|
|
|
|
import Heading from './Heading';
|
|
|
|
import Code from './Code';
|
|
|
|
import BigEmoji from './BigEmoji';
|
|
|
|
import OrderedList from './OrderedList';
|
|
|
|
import UnorderedList from './UnorderedList';
|
2022-02-17 15:27:01 +00:00
|
|
|
import { IUserMention, IUserChannel, TOnLinkPress } from '../interfaces';
|
2021-10-20 16:32:58 +00:00
|
|
|
import TaskList from './TaskList';
|
|
|
|
import MarkdownContext from './MarkdownContext';
|
2022-07-20 21:02:18 +00:00
|
|
|
import LineBreak from './LineBreak';
|
|
|
|
import { KaTeX } from './Katex';
|
2021-10-20 16:32:58 +00:00
|
|
|
|
|
|
|
interface IBodyProps {
|
2022-02-17 15:27:01 +00:00
|
|
|
tokens?: MarkdownAST;
|
|
|
|
mentions?: IUserMention[];
|
|
|
|
channels?: IUserChannel[];
|
2021-10-20 16:32:58 +00:00
|
|
|
getCustomEmoji?: Function;
|
2022-02-17 15:27:01 +00:00
|
|
|
onLinkPress?: TOnLinkPress;
|
|
|
|
navToRoomInfo?: Function;
|
|
|
|
useRealName?: boolean;
|
2021-10-20 16:32:58 +00:00
|
|
|
username: string;
|
|
|
|
baseUrl: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Body = ({
|
|
|
|
tokens,
|
|
|
|
mentions,
|
|
|
|
channels,
|
|
|
|
useRealName,
|
|
|
|
username,
|
|
|
|
navToRoomInfo,
|
|
|
|
getCustomEmoji,
|
|
|
|
baseUrl,
|
|
|
|
onLinkPress
|
2022-07-20 21:02:18 +00:00
|
|
|
}: IBodyProps): React.ReactElement | null => {
|
2022-02-17 15:27:01 +00:00
|
|
|
if (isEmpty(tokens)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<MarkdownContext.Provider
|
|
|
|
value={{
|
|
|
|
mentions,
|
|
|
|
channels,
|
|
|
|
useRealName,
|
|
|
|
username,
|
|
|
|
navToRoomInfo,
|
|
|
|
getCustomEmoji,
|
|
|
|
baseUrl,
|
|
|
|
onLinkPress
|
2022-08-08 21:02:08 +00:00
|
|
|
}}
|
|
|
|
>
|
2022-02-17 15:27:01 +00:00
|
|
|
{tokens?.map(block => {
|
|
|
|
switch (block.type) {
|
|
|
|
case 'BIG_EMOJI':
|
|
|
|
return <BigEmoji value={block.value} />;
|
|
|
|
case 'UNORDERED_LIST':
|
|
|
|
return <UnorderedList value={block.value} />;
|
|
|
|
case 'ORDERED_LIST':
|
|
|
|
return <OrderedList value={block.value} />;
|
|
|
|
case 'TASKS':
|
|
|
|
return <TaskList value={block.value} />;
|
|
|
|
case 'QUOTE':
|
|
|
|
return <Quote value={block.value} />;
|
|
|
|
case 'PARAGRAPH':
|
|
|
|
return <Paragraph value={block.value} />;
|
|
|
|
case 'CODE':
|
|
|
|
return <Code value={block.value} />;
|
|
|
|
case 'HEADING':
|
|
|
|
return <Heading value={block.value} level={block.level} />;
|
2022-07-20 21:02:18 +00:00
|
|
|
case 'LINE_BREAK':
|
|
|
|
return <LineBreak />;
|
|
|
|
// This prop exists, but not even on the web it is treated, so...
|
|
|
|
// https://github.com/RocketChat/Rocket.Chat/blob/develop/packages/gazzodown/src/Markup.tsx
|
|
|
|
// case 'LIST_ITEM':
|
|
|
|
// return <View />;
|
|
|
|
case 'KATEX':
|
|
|
|
return <KaTeX value={block.value} />;
|
2022-02-17 15:27:01 +00:00
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
})}
|
|
|
|
</MarkdownContext.Provider>
|
|
|
|
);
|
|
|
|
};
|
2021-10-20 16:32:58 +00:00
|
|
|
|
|
|
|
export default Body;
|