🧮 feat: Improve LaTeX rendering consistency (#3763)

* refactor: simplify LaTeX pre-processing for more consistent rendering, disables `singleDollarTextMath`

* refactor: disable singleDollarTextMath in all markdown components

* wip: first pass

* refactor: preserve code blocks and convert rather than preserve LaTeX delimiters

* refactor: remove unused escapeDollarNumber function from latex.ts
This commit is contained in:
Danny Avila 2024-08-23 13:45:27 -04:00 committed by GitHub
parent 967e8a1e92
commit ea5140ff0f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 156 additions and 3 deletions

View file

@ -8,7 +8,7 @@ import { useRecoilValue } from 'recoil';
import ReactMarkdown from 'react-markdown';
import type { PluggableList } from 'unified';
import rehypeHighlight from 'rehype-highlight';
import { cn, langSubset, validateIframe, processLaTeX, handleDoubleClick } from '~/utils';
import { langSubset, validateIframe, preprocessLaTeX, handleDoubleClick } from '~/utils';
import CodeBlock from '~/components/Messages/Content/CodeBlock';
import { useFileDownload } from '~/data-provider';
import useLocalize from '~/hooks/useLocalize';
@ -123,7 +123,7 @@ const Markdown = memo(({ content = '', isEdited, showCursor, isLatestMessage }:
let currentContent = content;
if (!isInitializing) {
currentContent = currentContent.replace('z-index: 1;', '') || '';
currentContent = LaTeXParsing ? processLaTeX(currentContent) : currentContent;
currentContent = LaTeXParsing ? preprocessLaTeX(currentContent) : currentContent;
}
const rehypePlugins: PluggableList = [