diff --git a/frontend/src/components/MarkdownText/MarkdownText.tsx b/frontend/src/components/MarkdownText/MarkdownText.tsx index c0e5919805..bfcfe9a35b 100644 --- a/frontend/src/components/MarkdownText/MarkdownText.tsx +++ b/frontend/src/components/MarkdownText/MarkdownText.tsx @@ -23,7 +23,28 @@ export const MarkdownText = ({ const processedRawString = useMemo(() => { // Create new line nodes for every new line in raw string so new lines gets rendered. if (multilineBreaks) { - return children.replace(/\n/gi, '  \n') + return ( + /** + * For lines that are contain a token that indents, + * we want to remove the whitespace before the newline + * so that new lines that come after these tokens + * can break out of the indentation group + * + * (-|\d+\.|\*): matching character tokens that indents + * -: "-" + * *: "*", + * \d+ : "1.", "2.", etc. + * + * \s: whitespace following the token, indentation groups must start with token followed by a whitespace character + * + * .*: any character, any number of times, this is the actual text content of the line + * + * \n: new line character + */ + children + .replace(/\n/g, '  \n') + .replace(/(\n(-|\d+\.|\*)\s.*\n)(  \n)/g, '$1 \n') + ) } return children }, [children, multilineBreaks])