From fad3b13895467d8db66ab0560be0398d002f8196 Mon Sep 17 00:00:00 2001 From: Andrii Ieroshenko Date: Tue, 6 Feb 2024 16:40:50 -0800 Subject: [PATCH] move escapeLatexDelimiters outside of RendermimeMarkdownBase to avoid redefinitions on every rerender --- .../src/components/rendermime-markdown.tsx | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/jupyter-ai/src/components/rendermime-markdown.tsx b/packages/jupyter-ai/src/components/rendermime-markdown.tsx index 44b61e71f..046c2b542 100644 --- a/packages/jupyter-ai/src/components/rendermime-markdown.tsx +++ b/packages/jupyter-ai/src/components/rendermime-markdown.tsx @@ -12,23 +12,23 @@ type RendermimeMarkdownProps = { rmRegistry: IRenderMimeRegistry; }; +/** + * Escape LaTeX delimeters by adding extra backslashes where needed for proper rendering by @jupyterlab/rendermime. + */ +function escapeLatexDelimiters(latexString: string) { + return latexString + .replace(/\\\(/g, '\\\\(') + .replace(/\\\)/g, '\\\\)') + .replace(/\\\[/g, '\\\\[') + .replace(/\\\]/g, '\\\\]'); +} + function RendermimeMarkdownBase(props: RendermimeMarkdownProps): JSX.Element { const [renderedContent, setRenderedContent] = useState( null ); const containerRef = useRef(null); - /** - * Escape LaTeX delimeters by adding extra backslashes where needed for proper rendering by @jupyterlab/rendermime. - */ - function escapeLatexDelimiters(latexString: string) { - return latexString - .replace(/\\\(/g, '\\\\(') - .replace(/\\\)/g, '\\\\)') - .replace(/\\\[/g, '\\\\[') - .replace(/\\\]/g, '\\\\]'); - } - useEffect(() => { const renderContent = async () => { const mdStr = escapeLatexDelimiters(props.markdownStr);