diff --git a/.changeset/kind-drinks-joke.md b/.changeset/kind-drinks-joke.md new file mode 100644 index 000000000000..b235f5556805 --- /dev/null +++ b/.changeset/kind-drinks-joke.md @@ -0,0 +1,5 @@ +--- +'@rocket.chat/meteor': patch +--- + +Fixed issue with asterisk-wrapped text not becoming bold when user enters profile custom status. diff --git a/apps/meteor/client/components/MarkdownText.tsx b/apps/meteor/client/components/MarkdownText.tsx index c9af942f6e1c..3670bcc7cec0 100644 --- a/apps/meteor/client/components/MarkdownText.tsx +++ b/apps/meteor/client/components/MarkdownText.tsx @@ -16,16 +16,21 @@ type MarkdownTextParams = { withTruncatedText: boolean; } & ComponentProps; +const walkTokens = (token: marked.Token) => { + const boldPattern = /^\*.*\*$|^\*.*|.*\*$/; + const italicPattern = /^__(?=\S)([\s\S]*?\S)__(?!_)|^_(?=\S)([\s\S]*?\S)_(?!_)/; + if (boldPattern.test(token.raw)) { + token.type = 'strong'; + } else if (italicPattern.test(token.raw)) { + token.type = 'em'; + } +}; + +marked.use({ walkTokens }); const documentRenderer = new marked.Renderer(); const inlineRenderer = new marked.Renderer(); const inlineWithoutBreaks = new marked.Renderer(); -marked.Lexer.rules.gfm = { - ...marked.Lexer.rules.gfm, - strong: /^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/, - em: /^__(?=\S)([\s\S]*?\S)__(?!_)|^_(?=\S)([\s\S]*?\S)_(?!_)/, -}; - const linkMarked = (href: string | null, _title: string | null, text: string): string => `${text} `; const paragraphMarked = (text: string): string => text; @@ -112,7 +117,6 @@ const MarkdownText = ({ const markedHtml = /inline/.test(variant) ? marked.parseInline(new Option(content).innerHTML, markedOptions) : marked.parse(new Option(content).innerHTML, markedOptions); - if (parseEmoji) { // We are using the old emoji parser here. This could come // with additional processing use, but is the workaround available right now.