Skip to content

Commit

Permalink
move escapeLatexDelimiters outside of RendermimeMarkdownBase to avoid…
Browse files Browse the repository at this point in the history
… redefinitions on every rerender
  • Loading branch information
andrii-i committed Feb 7, 2024
1 parent 9db6997 commit fad3b13
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions packages/jupyter-ai/src/components/rendermime-markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLElement | null>(
null
);
const containerRef = useRef<HTMLDivElement>(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);
Expand Down

0 comments on commit fad3b13

Please sign in to comment.