mirror of https://github.com/usememos/memos
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
672 B
TypeScript
29 lines
672 B
TypeScript
import TeX from "@matejmazur/react-katex";
|
|
import "katex/dist/katex.min.css";
|
|
|
|
export const LATEX_INLINE_REG = /\$(.+?)\$|\\\((.+?)\\\)/;
|
|
|
|
const inlineRenderer = (rawStr: string) => {
|
|
const matchResult = LATEX_INLINE_REG.exec(rawStr);
|
|
if (matchResult) {
|
|
let latexCode = "";
|
|
if (matchResult[1]) {
|
|
latexCode = matchResult[1];
|
|
} else if (matchResult[2]) {
|
|
latexCode = matchResult[2];
|
|
}
|
|
return (
|
|
<span className="max-w-full overflow-x-auto">
|
|
<TeX key={latexCode}>{latexCode}</TeX>
|
|
</span>
|
|
);
|
|
}
|
|
return rawStr;
|
|
};
|
|
|
|
export default {
|
|
name: "inlineLatex",
|
|
regexp: LATEX_INLINE_REG,
|
|
renderer: inlineRenderer,
|
|
};
|