diff --git a/package/src/components/Message/MessageSimple/utils/generateMarkdownText.ts b/package/src/components/Message/MessageSimple/utils/generateMarkdownText.ts index 2851be1376..4e116cc4f2 100644 --- a/package/src/components/Message/MessageSimple/utils/generateMarkdownText.ts +++ b/package/src/components/Message/MessageSimple/utils/generateMarkdownText.ts @@ -35,5 +35,11 @@ export const generateMarkdownText = (text?: string) => { resultText = resultText.replace(/[<"'>]/g, '\\$&'); + // Remove whitespaces that come directly after newlines except in code blocks where we deem this allowed. + resultText = resultText.replace(/(```[\s\S]*?```|`.*?`)|\n[ ]{2,}/g, (_, code) => { + if (code) return code; + return '\n'; + }); + return resultText; };