import { Fragment, type ReactNode } from "react";
type MessageContentProps = {
content: string;
};
function renderInline(text: string, keyPrefix: string): ReactNode[] {
const tokens = text.split(/(`[^`]+`|\*\*[^*]+\*\*|\[[^\]]+\]\([^)]+\))/g);
return tokens.map((token, index) => {
const key = `${keyPrefix}-${index}`;
if (token.startsWith("`") && token.endsWith("`")) {
return {token.slice(1, -1)};
}
if (token.startsWith("**") && token.endsWith("**")) {
return {token.slice(2, -2)};
}
const link = token.match(/^\[([^\]]+)\]\(([^)]+)\)$/);
if (link) {
return (
{link[1]}
);
}
return
{renderInline(paragraph.join(" "), `paragraph-${blocks.length}`)}
, ); paragraph = []; }; const flushList = () => { if (!list.length) return; blocks.push(
{codeLines.join("\n")}
,
);
codeLines = null;
codeLanguage = "";
return;
}
if (codeLines !== null) {
codeLines.push(line);
return;
}
if (!line.trim()) {
flushParagraph();
flushList();
return;
}
const heading = line.match(/^(#{1,3})\s+(.+)$/);
if (heading) {
flushParagraph();
flushList();
const level = heading[1].length;
const Heading = `h${level}` as "h1" | "h2" | "h3";
blocks.push(
{finalCodeText}
,
);
}
flushParagraph();
flushList();
return