Skip to content

Commit

Permalink
escape dollar signs in chat frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
dlqqq committed Oct 30, 2024
1 parent a25298e commit cab6156
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/jupyter-ai/src/components/rendermime-markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,20 @@ type RendermimeMarkdownProps = {
};

/**
* Takes \( and returns \\(. Escapes LaTeX delimeters by adding extra backslashes where needed for proper rendering by @jupyterlab/rendermime.
* Escapes LaTeX delimiters and single dollar signs by adding extra backslashes.
* Required for proper rendering of LaTeX markup by `@jupyterlab/rendermime`,
* and allows for `$` to be used literally to denote quantities of USD.
*
* The Jupyter AI system prompt should explicitly request that the LLM not use
* `$` as an inline math delimiter. This is the default behavior.
*/
function escapeLatexDelimiters(text: string) {
return text
.replace(/\\\(/g, '\\\\(')
.replace(/\\\)/g, '\\\\)')
.replace(/\\\[/g, '\\\\[')
.replace(/\\\]/g, '\\\\]');
.replace(/\\\]/g, '\\\\]')
.replace(/\$/g, '\\\\$');
}

function RendermimeMarkdownBase(props: RendermimeMarkdownProps): JSX.Element {
Expand Down

0 comments on commit cab6156

Please sign in to comment.