2021-10-20 16:32:58 +00:00
|
|
|
import React, { useContext } from 'react';
|
2021-10-27 13:13:20 +00:00
|
|
|
import { Text } from 'react-native';
|
2021-10-20 16:32:58 +00:00
|
|
|
import { Paragraph as ParagraphProps } from '@rocket.chat/message-parser';
|
|
|
|
|
|
|
|
import Hashtag from '../Hashtag';
|
|
|
|
import AtMention from '../AtMention';
|
2021-10-27 13:13:20 +00:00
|
|
|
import styles from '../styles';
|
2021-10-20 16:32:58 +00:00
|
|
|
import Link from './Link';
|
|
|
|
import Plain from './Plain';
|
|
|
|
import Bold from './Bold';
|
|
|
|
import Strike from './Strike';
|
|
|
|
import Italic from './Italic';
|
|
|
|
import Emoji from './Emoji';
|
|
|
|
import InlineCode from './InlineCode';
|
|
|
|
import Image from './Image';
|
|
|
|
import MarkdownContext from './MarkdownContext';
|
2022-07-20 21:02:18 +00:00
|
|
|
// import { InlineKaTeX, KaTeX } from './Katex';
|
2021-10-20 16:32:58 +00:00
|
|
|
|
|
|
|
interface IParagraphProps {
|
|
|
|
value: ParagraphProps['value'];
|
2023-02-02 03:17:09 +00:00
|
|
|
forceTrim?: boolean;
|
2021-10-20 16:32:58 +00:00
|
|
|
}
|
|
|
|
|
2023-02-02 03:17:09 +00:00
|
|
|
const Inline = ({ value, forceTrim }: IParagraphProps): React.ReactElement | null => {
|
2021-10-20 16:32:58 +00:00
|
|
|
const { useRealName, username, navToRoomInfo, mentions, channels } = useContext(MarkdownContext);
|
|
|
|
return (
|
2021-10-27 13:13:20 +00:00
|
|
|
<Text style={styles.inline}>
|
2023-02-02 03:17:09 +00:00
|
|
|
{value.map((block, index) => {
|
|
|
|
// We are forcing trim when is a `[ ](https://https://open.rocket.chat/) plain_text`
|
|
|
|
// to clean the empty spaces
|
|
|
|
if (forceTrim) {
|
|
|
|
if (index === 0 && block.type === 'LINK') {
|
2023-11-13 17:00:00 +00:00
|
|
|
if (!Array.isArray(block.value.label)) {
|
|
|
|
block.value.label.value = block.value?.label?.value?.toString().trimLeft();
|
|
|
|
} else {
|
|
|
|
// @ts-ignore - we are forcing the value to be a string
|
|
|
|
block.value.label.value = block?.value?.label?.[0]?.value?.toString().trimLeft();
|
|
|
|
}
|
2023-02-02 03:17:09 +00:00
|
|
|
}
|
|
|
|
if (index === 1 && block.type !== 'LINK') {
|
|
|
|
block.value = block.value?.toString().trimLeft();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-20 16:32:58 +00:00
|
|
|
switch (block.type) {
|
|
|
|
case 'IMAGE':
|
|
|
|
return <Image value={block.value} />;
|
|
|
|
case 'PLAIN_TEXT':
|
|
|
|
return <Plain value={block.value} />;
|
|
|
|
case 'BOLD':
|
|
|
|
return <Bold value={block.value} />;
|
|
|
|
case 'STRIKE':
|
|
|
|
return <Strike value={block.value} />;
|
|
|
|
case 'ITALIC':
|
|
|
|
return <Italic value={block.value} />;
|
|
|
|
case 'LINK':
|
|
|
|
return <Link value={block.value} />;
|
|
|
|
case 'MENTION_USER':
|
|
|
|
return (
|
|
|
|
<AtMention
|
|
|
|
mention={block.value.value}
|
|
|
|
useRealName={useRealName}
|
|
|
|
username={username}
|
|
|
|
navToRoomInfo={navToRoomInfo}
|
|
|
|
mentions={mentions}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
case 'EMOJI':
|
2022-07-06 20:01:33 +00:00
|
|
|
return <Emoji block={block} />;
|
2021-10-20 16:32:58 +00:00
|
|
|
case 'MENTION_CHANNEL':
|
2022-07-04 18:10:14 +00:00
|
|
|
return <Hashtag hashtag={block.value.value} navToRoomInfo={navToRoomInfo} channels={channels} />;
|
2021-10-20 16:32:58 +00:00
|
|
|
case 'INLINE_CODE':
|
|
|
|
return <InlineCode value={block.value} />;
|
2022-07-20 21:02:18 +00:00
|
|
|
case 'INLINE_KATEX':
|
|
|
|
// return <InlineKaTeX value={block.value} />;
|
|
|
|
return <Text>{block.value}</Text>;
|
2021-10-20 16:32:58 +00:00
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
})}
|
2021-10-27 13:13:20 +00:00
|
|
|
</Text>
|
2021-10-20 16:32:58 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Inline;
|