import { BlockMath, InlineMath } from "react-katex";

export const renderQuestionText = (text: string) => {
  const parts = text.split(/(\$\$.*?\$\$|\$.*?\$)/g);

  return (
    <>
      {parts.map((part, index) => {
        if (part.startsWith("$$")) {
          return <BlockMath key={index}>{part.slice(2, -2)}</BlockMath>;
        }
        if (part.startsWith("$")) {
          return <InlineMath key={index}>{part.slice(1, -1)}</InlineMath>;
        }
        return <span key={index}>{part}</span>;
      })}
    </>
  );
};
