import { FC, memo, useMemo } from "react";
import ReactMarkdown, { Options, Components } from "react-markdown";
import { CodeBlock } from "./CodeBlock";
import remarkGfm from "remark-gfm";
import remarkMath from "remark-math";
import rehypeRaw from "rehype-raw";
const defaultComponents: Components = {
a({ children, ...props }) {
return (
{children}
);
},
// @ts-expect-error -- inline
code({ children, className, inline, ...props }) {
if (Array.isArray(children) && children.length) {
if (children[0] == "▍") {
return (
▍
);
}
children[0] = (children?.[0] as string).replace("`▍`", "▍");
}
const match = /language-(\w+)/.exec(className || "");
// Detect inline code: if it has a language class or contains newlines, it's likely a code block
// Otherwise, treat it as inline code
const hasLanguage = match && match[1];
const content = String(children);
const hasNewlines = content.includes("\n");
const isInline = !hasLanguage && !hasNewlines;
if (isInline) {
return (
{children}
);
}
return (
{children}
),
blockquote: ({ children, ...props }) => (
{children}), ul: ({ children, ...props }) => (