diff --git a/src/components/StylizedText.tsx b/src/components/StylizedText.tsx index 852742ef698d45c05f0b8b24e3db4c2863add207..6fc4de54dee44d54d92da96e6f24976453d7e850 100644 --- a/src/components/StylizedText.tsx +++ b/src/components/StylizedText.tsx @@ -25,6 +25,16 @@ export function StylizedText({ str = str.replaceAll(/<strong>(.*?)<\/strong>/gs, "**$1**"); str = str.replaceAll(/<p>(.*?)<\/p>/gs, "$1\n\n"); str = str.replaceAll(/<!--(.*?)-->/gs, ""); + + // first test if there is any markdown in the string at all + // markdown rendering is expensive (~1ms per Component) so we want to avoid it if possible + // this is a very simple test and will not catch all cases, but it will never give a false positive + if (!str.match(/[*#[\]\d(`>-]/)) { + if (mapParagraphToSpan) + return str.split("\n\n").map((line, index) => <span key={index}>{line}</span>); + return str.split("\n\n").map((line, index) => <p key={index}>{line}</p>); + } + return ( <Suspense fallback={str}> <LazyMarkdown