fix: multiple inline latex parsing (#2214)

This commit is contained in:
Kada Liao 2023-09-13 17:58:52 +08:00 committed by GitHub
parent 04595a5fb1
commit 9600fbb609
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,24 +1,20 @@
import TeX from "@matejmazur/react-katex";
import "katex/dist/katex.min.css";
export const LATEX_INLINE_REG = /\$(.+?)\$|\\\(([^\\]+)\\\)/g;
export const LATEX_INLINE_REG = /\$(.+?)\$|\\\((.+?)\\\)/;
const inlineRenderer = (rawStr: string) => {
const matchResult = LATEX_INLINE_REG.exec(rawStr);
if (!matchResult) {
return rawStr;
if (matchResult) {
let latexCode = "";
if (matchResult[1]) {
latexCode = matchResult[1];
} else if (matchResult[2]) {
latexCode = matchResult[2];
}
return <TeX key={latexCode}>{latexCode}</TeX>;
}
let latexCode = "";
if (matchResult[1]) {
// $
latexCode = matchResult[1];
} else if (matchResult[2]) {
// \( and \)
latexCode = matchResult[2];
}
return <TeX>{latexCode}</TeX>;
return rawStr;
};
export default {