{codeM[1]}
);
i += codeM[0].length;
continue;
}
// Bold: **...** or __...__
const boldM = rest.match(/^(\*\*|__)(.+?)\1/);
if (boldM) {
push(
{renderInline(boldM[2]!, `${baseKey}-b${n}`)}
);
i += boldM[0].length;
continue;
}
// Italic: *...* or _..._
const italicM = rest.match(/^(\*|_)([^*_\n]+?)\1/);
if (italicM) {
push(
{renderInline(italicM[2]!, `${baseKey}-i${n}`)}
);
i += italicM[0].length;
continue;
}
// Strikethrough
const strikeM = rest.match(/^~~(.+?)~~/);
if (strikeM) {
push(
{renderInline(strikeM[1]!, `${baseKey}-s${n}`)}
);
i += strikeM[0].length;
continue;
}
// Markdown link
const linkM = rest.match(/^\[([^\]]+)\]\(([^)\s]+)(?:\s+"[^"]*")?\)/);
if (linkM) {
push(
{renderInline(linkM[1]!, `${baseKey}-l${n}`)}
);
i += linkM[0].length;
continue;
}
// Auto-link
const urlM = rest.match(/^https?:\/\/[^\s<>()]+[^\s<>().,!?;:'"]/);
if (urlM) {
push(
{urlM[0]}
);
i += urlM[0].length;
continue;
}
buf += text[i]!;
i++;
}
flush();
return out;
}
/** Render a single list item, handling [ ] / [x] task list prefixes. */
function renderListItem(item: string, key: string): React.ReactNode {
const taskMatch = item.match(/^\[([ xX])\]\s+(.*)$/s);
if (taskMatch) {
const checked = taskMatch[1]!.toLowerCase() === "x";
return (
{renderInline(taskMatch[2]!, key)}
);
}
return renderInline(item, key);
}
interface MarkdownContentProps {
text: string;
/** Tighter spacing for nested contexts (list items, quotes). */
dense?: boolean;
}
const HEADING_STYLES = [
"text-[18px] font-semibold text-gray-50 mt-2 pb-1 border-b border-surface-3",
"text-[16px] font-semibold text-gray-50 mt-2",
"text-[15px] font-semibold text-gray-100",
"text-sm font-semibold text-gray-100",
"text-sm font-medium text-gray-200",
"text-xs font-medium text-gray-300 uppercase tracking-wider",
];
export function MarkdownContent({ text, dense = false }: MarkdownContentProps) {
const blocks = parseBlocks(text);
const gap = dense ? "space-y-1.5" : "space-y-2.5";
return (
{renderInline(b.text, `q${idx}`)}); case "hr": return (
| {renderInline(cell, `th${idx}-${i}`)} | ))}
|---|
| {renderInline(cell, `td${idx}-${ri}-${ci}`)} | ))}
{renderInline(b.text, `p${idx}`)}
); } })}