-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: mentions and emojis inside bold, italic and strikethrough (#29391)
- Loading branch information
1 parent
d91e480
commit e01bbcc
Showing
9 changed files
with
260 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@rocket.chat/gazzodown': minor | ||
--- | ||
|
||
Fixed mentions and emojis inside inside bold, italic or strikethrough texts | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,62 @@ | ||
import type * as MessageParser from '@rocket.chat/message-parser'; | ||
import type { ReactElement } from 'react'; | ||
|
||
import EmojiElement from '../emoji/EmojiElement'; | ||
import ChannelMentionElement from '../mentions/ChannelMentionElement'; | ||
import UserMentionElement from '../mentions/UserMentionElement'; | ||
import ItalicSpan from './ItalicSpan'; | ||
import LinkSpan from './LinkSpan'; | ||
import PlainSpan from './PlainSpan'; | ||
import StrikeSpan from './StrikeSpan'; | ||
|
||
type MessageBlock = | ||
| MessageParser.Emoji | ||
| MessageParser.ChannelMention | ||
| MessageParser.UserMention | ||
| MessageParser.Link | ||
| MessageParser.MarkupExcluding<MessageParser.Bold>; | ||
|
||
type BoldSpanProps = { | ||
children: (MessageParser.Link | MessageParser.MarkupExcluding<MessageParser.Bold>)[]; | ||
children: MessageBlock[]; | ||
}; | ||
|
||
const BoldSpan = ({ children }: BoldSpanProps): ReactElement => ( | ||
<strong> | ||
<> | ||
{children.map((block, index) => { | ||
switch (block.type) { | ||
case 'LINK': | ||
return <LinkSpan key={index} href={block.value.src.value} label={block.value.label} />; | ||
if (block.type === 'LINK' || block.type === 'PLAIN_TEXT' || block.type === 'STRIKE' || block.type === 'ITALIC') { | ||
return <strong key={index}>{renderBlockComponent(block, index)}</strong>; | ||
} | ||
return renderBlockComponent(block, index); | ||
})} | ||
</> | ||
); | ||
|
||
case 'PLAIN_TEXT': | ||
return <PlainSpan key={index} text={block.value} />; | ||
const renderBlockComponent = (block: MessageBlock, index: number): ReactElement | null => { | ||
switch (block.type) { | ||
case 'EMOJI': | ||
return <EmojiElement key={index} {...block} />; | ||
|
||
case 'STRIKE': | ||
return <StrikeSpan key={index} children={block.value} />; | ||
case 'MENTION_USER': | ||
return <UserMentionElement key={index} mention={block.value.value} />; | ||
|
||
case 'ITALIC': | ||
return <ItalicSpan key={index} children={block.value} />; | ||
case 'MENTION_CHANNEL': | ||
return <ChannelMentionElement key={index} mention={block.value.value} />; | ||
|
||
default: | ||
return null; | ||
} | ||
})} | ||
</strong> | ||
); | ||
case 'PLAIN_TEXT': | ||
return <PlainSpan key={index} text={block.value} />; | ||
|
||
case 'LINK': | ||
return <LinkSpan key={index} href={block.value.src.value} label={block.value.label} />; | ||
|
||
case 'STRIKE': | ||
return <StrikeSpan key={index} children={block.value} />; | ||
|
||
case 'ITALIC': | ||
return <ItalicSpan key={index} children={block.value} />; | ||
|
||
default: | ||
return null; | ||
} | ||
}; | ||
|
||
export default BoldSpan; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.