mirror of
https://github.com/usememos/memos.git
synced 2025-10-09 05:46:22 +08:00
fix: multiple inline latex parsing (#2214)
This commit is contained in:
parent
04595a5fb1
commit
9600fbb609
1 changed files with 10 additions and 14 deletions
|
@ -1,24 +1,20 @@
|
||||||
import TeX from "@matejmazur/react-katex";
|
import TeX from "@matejmazur/react-katex";
|
||||||
import "katex/dist/katex.min.css";
|
import "katex/dist/katex.min.css";
|
||||||
|
|
||||||
export const LATEX_INLINE_REG = /\$(.+?)\$|\\\(([^\\]+)\\\)/g;
|
export const LATEX_INLINE_REG = /\$(.+?)\$|\\\((.+?)\\\)/;
|
||||||
|
|
||||||
const inlineRenderer = (rawStr: string) => {
|
const inlineRenderer = (rawStr: string) => {
|
||||||
const matchResult = LATEX_INLINE_REG.exec(rawStr);
|
const matchResult = LATEX_INLINE_REG.exec(rawStr);
|
||||||
if (!matchResult) {
|
if (matchResult) {
|
||||||
return rawStr;
|
|
||||||
}
|
|
||||||
|
|
||||||
let latexCode = "";
|
let latexCode = "";
|
||||||
|
|
||||||
if (matchResult[1]) {
|
if (matchResult[1]) {
|
||||||
// $
|
|
||||||
latexCode = matchResult[1];
|
latexCode = matchResult[1];
|
||||||
} else if (matchResult[2]) {
|
} else if (matchResult[2]) {
|
||||||
// \( and \)
|
|
||||||
latexCode = matchResult[2];
|
latexCode = matchResult[2];
|
||||||
}
|
}
|
||||||
return <TeX>{latexCode}</TeX>;
|
return <TeX key={latexCode}>{latexCode}</TeX>;
|
||||||
|
}
|
||||||
|
return rawStr;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|
Loading…
Add table
Reference in a new issue