import MarkdownIt from 'markdown-it';
// @ts-ignore
import markdownItKatex from 'markdown-it-katex';

// 创建 markdown-it 实例并配置 KaTeX 支持
export const createMarkdownRenderer = () => {
  const md = new MarkdownIt({
    html: true,
    linkify: true,
    typographer: true,
  });

  // 使用 markdown-it-katex 插件
  md.use(markdownItKatex, {
    blockClass: 'math-display',
    errorColor: '#cc0000',
    macros: {
      "\\RR": "\\mathbb{R}"
    }
  });

  return md;
};

// 渲染 markdown 内容
export const renderMarkdown = (content: string): string => {
  const md = createMarkdownRenderer();
  return md.render(content);
};
