Merge pull request #3150 from continuedev/dallin/latex-truncation-fix
Latex truncation fix
This commit is contained in:
commit
06bc5a5d90
2 changed files with 18 additions and 1 deletions
|
|
@ -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 (
|
||||
|
|
|
|||
13
gui/src/components/markdown/utils/fixDoubleDollarLatex.ts
Normal file
13
gui/src/components/markdown/utils/fixDoubleDollarLatex.ts
Normal 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;
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue