import { math_escape, math_unescape } from "@cocalc/util/markdown-utils";
import { remove_math, replace_math } from "@cocalc/util/mathjax-utils";
import { latexMathToHtml } from "@cocalc/frontend/misc/math-to-html";
import { replace_all } from "@cocalc/util/misc";
import { replaceMathBracketDelims } from "./util";
interface Props {
data: string;
inMarkdown?: boolean;
}
export default function DefaultMath({ data }: Props) {
data = replaceMathBracketDelims(data);
const [text, math] = remove_math(math_escape(data));
if (math.length == 0) {
return <>{data}</>;
}
for (let i = 0; i < math.length; i++) {
math[i] = latexMathToHtml(math[i]);
}
const __html = replace_all(
math_unescape(replace_math(text, math)),
"\\$",
"$"
);
return <span dangerouslySetInnerHTML={{ __html }}></span>;
}