diff --git a/gui/src/components/markdown/StyledMarkdownPreview.tsx b/gui/src/components/markdown/StyledMarkdownPreview.tsx index 1f7246cba..46a52a97a 100644 --- a/gui/src/components/markdown/StyledMarkdownPreview.tsx +++ b/gui/src/components/markdown/StyledMarkdownPreview.tsx @@ -25,6 +25,7 @@ import { remarkTables } from "./utils/remarkTables"; import { SyntaxHighlightedPre } from "./SyntaxHighlightedPre"; import { patchNestedMarkdown } from "./utils/patchNestedMarkdown"; import { useAppSelector } from "../../redux/hooks"; +import { fixDoubleDollarNewLineLatex } from "./utils/fixDoubleDollarLatex"; const StyledMarkdown = styled.div<{ fontSize?: number; @@ -298,7 +299,10 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview( }); useEffect(() => { - setMarkdownSource(patchNestedMarkdown(props.source ?? "")); + setMarkdownSource( + // some patches to source markdown are applied here: + fixDoubleDollarNewLineLatex(patchNestedMarkdown(props.source ?? "")), + ); }, [props.source]); return ( diff --git a/gui/src/components/markdown/utils/fixDoubleDollarLatex.ts b/gui/src/components/markdown/utils/fixDoubleDollarLatex.ts new file mode 100644 index 000000000..98b09f596 --- /dev/null +++ b/gui/src/components/markdown/utils/fixDoubleDollarLatex.ts @@ -0,0 +1,13 @@ +/* +Currently double dollar latext with new lines causes truncation error +So this pseudo-remark plugin removes internal newlines with double dollar signs +*/ +export function fixDoubleDollarNewLineLatex(text: string): string { + // Match LaTeX blocks delimited by $$ with newlines + const pattern = /\$\$(?:\r?\n)(.*?)(?:\r?\n)\$\$/gms; + + // Replace each matched block with $$ without newline + const replacedText = text.replace(pattern, "$$$$$1$$$$"); + + return replacedText; +}