import Markdown from 'react-markdown' import remarkMath from 'remark-math' import remarkGfm from 'remark-gfm' import rehypeKatex from 'rehype-katex' import 'katex/dist/katex.min.css' const REMARK_PLUGINS = [remarkGfm, [remarkMath, { singleDollarTextMath: true }]] const REHYPE_PLUGINS = [rehypeKatex] const TABLE_COMPONENTS = { table: ({ children }) => (
{children}
), th: ({ children }) => ( {children} ), td: ({ children }) => ( {children} ), } /** * Inline math + markdown renderer (wraps in ``). * Suitable for question stems, answer choices, and short math expressions. * Supports $…$ and $$…$$ LaTeX via KaTeX. * * @example * Tính $\int_0^1 x^2 \, dx$ */ export function MathText({ children, className, style }) { return ( {c}, ol: ({ children: c }) => {c}, ul: ({ children: c }) => {c}, li: ({ children: c }) => {c}, ...TABLE_COMPONENTS, }} > {children ?? ''} ) } /** * Block math + markdown renderer (preserves paragraph breaks). * Suitable for explanations, study plan text, and multi-paragraph content. * * @example * {explanationMarkdown} */ export function MathBlock({ children, className }) { return (

{c}

, strong: ({ children: c }) => {c}, em: ({ children: c }) => {c}, ul: ({ children: c }) =>
    {c}
, ol: ({ children: c }) =>
    {c}
, li: ({ children: c }) =>
  • {c}
  • , ...TABLE_COMPONENTS, }} > {children ?? ''}
    ) }