Merge pull request #3150 from continuedev/dallin/latex-truncation-fix

Latex truncation fix
This commit is contained in:
Nate Sesti 2024-12-03 21:17:13 -08:00 • committed by GitHub
commit 06bc5a5d90
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 1 deletions

View file

@ -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 (

View file

@ -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;
}