From bf22248025eeec9f9812a9c9be692bba481c7177 Mon Sep 17 00:00:00 2001 From: michael Date: Sun, 25 Jan 2026 08:26:31 -0600 Subject: [PATCH] Fix PDF export formatting by parsing HTML and bullet text Co-Authored-By: Claude Opus 4.5 --- frontend/components/PDFReport.tsx | 57 +++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/frontend/components/PDFReport.tsx b/frontend/components/PDFReport.tsx index fa39dc4..5399147 100755 --- a/frontend/components/PDFReport.tsx +++ b/frontend/components/PDFReport.tsx @@ -11,6 +11,59 @@ interface PDFReportProps { proofs: any[]; } +const formatFeedbackTextForPDF = (text: string): React.ReactNode => { + if (!text) return null; + + // Normalize HTML tags and bullet characters + let normalizedText = text + .replace(/<\/li>/gi, '\n') + .replace(/<\/ul>/gi, '\n') + .replace(/]*>/gi, '') + .replace(/]*>/gi, '• ') + .replace(/<[^>]+>/g, '') + .replace(/\s*•\s*/g, '\n• ') + .replace(/\n{2,}/g, '\n') + .trim(); + + const lines = normalizedText.split('\n').filter(line => line.trim()); + + const bulletLines: string[] = []; + const introLines: string[] = []; + + lines.forEach(line => { + const trimmed = line.trim(); + if (trimmed.startsWith('•')) { + bulletLines.push(trimmed.replace(/^•\s*/, '').trim()); + } else if (trimmed) { + if (bulletLines.length === 0) { + introLines.push(trimmed); + } else { + const lastBullet = bulletLines.pop(); + if (lastBullet) { + bulletLines.push(`${lastBullet} ${trimmed}`); + } else { + bulletLines.push(trimmed); + } + } + } + }); + + return ( + <> + {introLines.length > 0 && ( +

{introLines.join(' ')}

+ )} + {bulletLines.length > 0 && ( +
    + {bulletLines.map((item, index) => ( +
  • {item}
  • + ))} +
+ )} + + ); +}; + const RagStatusBadge: React.FC<{ status: RagStatus }> = ({ status }) => { let bgColor = '#E5E7EB'; // Gray for Error let textColor = '#1F2937'; @@ -115,7 +168,7 @@ export const PDFReport: React.FC = ({ campaignName, proofs }) =>

"{feedback.financialPromotionReason}"

)} -

{feedback.leadAgentSummary}

+
{formatFeedbackTextForPDF(feedback.leadAgentSummary)}
@@ -129,7 +182,7 @@ export const PDFReport: React.FC = ({ campaignName, proofs }) => -

{review.feedback}

+
{formatFeedbackTextForPDF(review.feedback)}
{review.issues && review.issues.length > 0 && (
Actionable Issues: