Skip to content
11 changes: 9 additions & 2 deletions packages/gazzodown/src/elements/BoldSpan.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type * as MessageParser from '@rocket.chat/message-parser';
import type { ReactElement } from 'react';
import { lazy } from 'react';

import EmojiElement from '../emoji/EmojiElement';
import ChannelMentionElement from '../mentions/ChannelMentionElement';
Expand All @@ -9,12 +10,15 @@ import LinkSpan from './LinkSpan';
import PlainSpan from './PlainSpan';
import StrikeSpan from './StrikeSpan';

const CodeElement = lazy(() => import('../code/CodeElement'));

type MessageBlock =
| MessageParser.Emoji
| MessageParser.ChannelMention
| MessageParser.UserMention
| MessageParser.Link
| MessageParser.MarkupExcluding<MessageParser.Bold>;
| MessageParser.MarkupExcluding<MessageParser.Bold>
| MessageParser.InlineCode;

type BoldSpanProps = {
children: MessageBlock[];
Expand All @@ -23,7 +27,7 @@ type BoldSpanProps = {
const BoldSpan = ({ children }: BoldSpanProps): ReactElement => (
<>
{children.map((block, index) => {
if (block.type === 'LINK' || block.type === 'PLAIN_TEXT' || block.type === 'STRIKE' || block.type === 'ITALIC') {
if (block.type === 'LINK' || block.type === 'PLAIN_TEXT' || block.type === 'STRIKE' || block.type === 'ITALIC' || block.type === 'INLINE_CODE' ) {
return <strong key={index}>{renderBlockComponent(block, index)}</strong>;
}
return renderBlockComponent(block, index);
Expand Down Expand Up @@ -54,6 +58,9 @@ const renderBlockComponent = (block: MessageBlock, index: number): ReactElement
case 'ITALIC':
return <ItalicSpan key={index} children={block.value} />;

case 'INLINE_CODE':
return <CodeElement key={index} code={block.value.value} />;

default:
return null;
}
Expand Down
11 changes: 9 additions & 2 deletions packages/gazzodown/src/elements/ItalicSpan.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type * as MessageParser from '@rocket.chat/message-parser';
import type { ReactElement } from 'react';
import { lazy } from 'react';

import EmojiElement from '../emoji/EmojiElement';
import ChannelMentionElement from '../mentions/ChannelMentionElement';
Expand All @@ -9,12 +10,15 @@ import LinkSpan from './LinkSpan';
import PlainSpan from './PlainSpan';
import StrikeSpan from './StrikeSpan';

const CodeElement = lazy(() => import('../code/CodeElement'));

type MessageBlock =
| MessageParser.Emoji
| MessageParser.ChannelMention
| MessageParser.UserMention
| MessageParser.Link
| MessageParser.MarkupExcluding<MessageParser.Italic>;
| MessageParser.MarkupExcluding<MessageParser.Italic>
| MessageParser.InlineCode;

type ItalicSpanProps = {
children: MessageBlock[];
Expand All @@ -23,7 +27,7 @@ type ItalicSpanProps = {
const ItalicSpan = ({ children }: ItalicSpanProps): ReactElement => (
<>
{children.map((block, index) => {
if (block.type === 'LINK' || block.type === 'PLAIN_TEXT' || block.type === 'STRIKE' || block.type === 'BOLD') {
if (block.type === 'LINK' || block.type === 'PLAIN_TEXT' || block.type === 'STRIKE' || block.type === 'BOLD' || block.type === 'INLINE_CODE') {
return <em key={index}>{renderBlockComponent(block, index)}</em>;
}
return renderBlockComponent(block, index);
Expand Down Expand Up @@ -54,6 +58,9 @@ const renderBlockComponent = (block: MessageBlock, index: number): ReactElement
case 'BOLD':
return <BoldSpan key={index} children={block.value} />;

case 'INLINE_CODE':
return <CodeElement key={index} code={block.value.value} />;

default:
return null;
}
Expand Down
11 changes: 9 additions & 2 deletions packages/gazzodown/src/elements/StrikeSpan.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type * as MessageParser from '@rocket.chat/message-parser';
import type { ReactElement } from 'react';
import { lazy } from 'react';

import EmojiElement from '../emoji/EmojiElement';
import ChannelMentionElement from '../mentions/ChannelMentionElement';
Expand All @@ -9,12 +10,15 @@ import ItalicSpan from './ItalicSpan';
import LinkSpan from './LinkSpan';
import PlainSpan from './PlainSpan';

const CodeElement = lazy(() => import('../code/CodeElement'));

type MessageBlock =
| MessageParser.Emoji
| MessageParser.ChannelMention
| MessageParser.UserMention
| MessageParser.Link
| MessageParser.MarkupExcluding<MessageParser.Strike>;
| MessageParser.MarkupExcluding<MessageParser.Strike>
| MessageParser.InlineCode;

type StrikeSpanProps = {
children: MessageBlock[];
Expand All @@ -23,7 +27,7 @@ type StrikeSpanProps = {
const StrikeSpan = ({ children }: StrikeSpanProps): ReactElement => (
<>
{children.map((block, index) => {
if (block.type === 'LINK' || block.type === 'PLAIN_TEXT' || block.type === 'ITALIC' || block.type === 'BOLD') {
if (block.type === 'LINK' || block.type === 'PLAIN_TEXT' || block.type === 'ITALIC' || block.type === 'BOLD' || block.type === 'INLINE_CODE') {
return <del key={index}>{renderBlockComponent(block, index)}</del>;
}
return renderBlockComponent(block, index);
Expand Down Expand Up @@ -54,6 +58,9 @@ const renderBlockComponent = (block: MessageBlock, index: number): ReactElement
case 'BOLD':
return <BoldSpan key={index} children={block.value} />;

case 'INLINE_CODE':
return <CodeElement key={index} code={block.value.value} />;

default:
return null;
}
Expand Down