From d357bc78ec988addf792a7c86ccce836d6775046 Mon Sep 17 00:00:00 2001 From: Peter Krenesky Date: Sun, 28 May 2023 17:33:27 -0700 Subject: [PATCH] HighlightText now retains spacing and linebreaks --- frontend/components/HighlightText.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/frontend/components/HighlightText.js b/frontend/components/HighlightText.js index 5b727dde..f619b4ed 100644 --- a/frontend/components/HighlightText.js +++ b/frontend/components/HighlightText.js @@ -11,24 +11,23 @@ const HighlightText = ({ content }) => { const { mention, artifact } = useChatColorMode(); const formattedContent = React.useMemo(() => { - // Match @mentions and {artifacts} and return an array of Chakra Text components - return content.split(" ").map((word, idx) => { - if (word.startsWith("@")) { - // Word is a mention + return content.split(/(\s|\n)/).map((segment, idx) => { + if (segment.startsWith("@")) { return ( - {word + " "} + {segment} ); - } else if (word.startsWith("{") && word.endsWith("}")) { - // Word is an artifact + } else if (segment.startsWith("{") && segment.endsWith("}")) { return ( - {word + " "} + {segment} ); + } else if (segment === "\n") { + return
; } else { - return word + " "; + return segment; } }); }, [content]);