'use client'; import React from 'react'; import { ShieldCheck, CheckCircle2, Lock, Cpu, Zap, FileCheck, AlertCircle, ExternalLink, ChevronRight } from 'lucide-react'; interface RichTextSectionProps { markdown?: string; } export function RichTextSection({ markdown = '' }: RichTextSectionProps) { // Helper to parse inline markdown (bold, italic, code, links) const renderInline = (text: string): React.ReactNode[] => { // Split on markdown tokens: **bold**, *italic*, `code`, [link](url) const regex = /(\*\*.*?\*\*|\*.*?\*|`.*?`|\[.*?\]\(.*?\))/g; const parts = text.split(regex); return parts.map((part, i) => { if (!part) return null; if (part.startsWith('**') && part.endsWith('**')) { return ( {part.slice(2, -2)} ); } if (part.startsWith('*') && part.endsWith('*')) { return ( {part.slice(1, -1)} ); } if (part.startsWith('`') && part.endsWith('`')) { return ( {part.slice(1, -1)} ); } if (part.startsWith('[') && part.includes('](') && part.endsWith(')')) { const linkMatch = part.match(/\[(.*?)\]\((.*?)\)/); if (linkMatch) { const [, linkText, linkHref] = linkMatch; return ( {linkText} {linkHref.startsWith('http') && } ); } } return {part}; }); }; const renderContent = (content: string) => { const lines = content.split('\n'); const nodes: React.ReactNode[] = []; let tableRows: string[][] = []; let inTable = false; const flushTable = (keyIdx: number) => { if (tableRows.length === 0) return null; const headers = tableRows[0]; const rows = tableRows.slice(2); // Skip separator row const tableNode = (
{headers.map((h, hIdx) => ( ))} {rows.map((row, rIdx) => ( {row.map((cell, cIdx) => ( ))} ))}
{renderInline(h.trim())}
{renderInline(cell.trim())}
); tableRows = []; inTable = false; return tableNode; }; for (let idx = 0; idx < lines.length; idx++) { const line = lines[idx]; // Table parsing if (line.trim().startsWith('|') && line.trim().endsWith('|')) { inTable = true; const cols = line.trim().slice(1, -1).split('|'); tableRows.push(cols); continue; } else if (inTable) { const tableNode = flushTable(idx); if (tableNode) nodes.push(tableNode); } // Horizontal Divider if (line.trim() === '---' || line.trim() === '***') { nodes.push(
); continue; } // Headings if (line.startsWith('## ')) { nodes.push(

{line.replace('## ', '')}

); continue; } if (line.startsWith('### ')) { nodes.push(

{renderInline(line.replace('### ', ''))}

); continue; } if (line.startsWith('#### ')) { nodes.push(

{renderInline(line.replace('#### ', ''))}

); continue; } // Blockquotes / Callout Boxes if (line.startsWith('> ')) { nodes.push(
{renderInline(line.replace('> ', ''))}
); continue; } // Bullet List items if (line.trim().startsWith('- ') || line.trim().startsWith('* ')) { nodes.push(
{renderInline(line.trim().slice(2))}
); continue; } // Numbered List items (e.g. "1. ", "12. ") const numMatch = line.trim().match(/^(\d+)\.\s+(.*)/); if (numMatch) { const num = numMatch[1]; const rest = numMatch[2]; nodes.push(
{num}
{renderInline(rest)}
); continue; } // Empty Lines if (line.trim().length === 0) { nodes.push(
); continue; } // Normal Paragraph nodes.push(

{renderInline(line)}

); } if (inTable) { const tableNode = flushTable(lines.length); if (tableNode) nodes.push(tableNode); } return nodes; }; return (
{renderContent(markdown)}
); }