`;
const insightsHtml = insightsText
.replace(/### (.*?)\n/g, '
') .replace(/\n- /g, '/,'')
.replace(/\*\*(.*?)\*\*/g, '$1');
summaryContentContainer.innerHTML = resultsHtml + insightsHtml;
};
// --- PDF GENERATION ---
const handleDownloadPdf = () => {
const content = document.getElementById('pdf-content');
if (!content) return;
html2canvas(content, { scale: 2, useCORS: true, backgroundColor: '#ffffff' })
.then(canvas => {
const imgData = canvas.toDataURL('image/png');
const pdf = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' });
const pdfWidth = pdf.internal.pageSize.getWidth();
const pdfHeight = pdf.internal.pageSize.getHeight();
const ratio = canvas.width / canvas.height;
const imgWidth = pdfWidth - 20;
let imgHeight = imgWidth / ratio;
let heightLeft = imgHeight;
let position = 10;
pdf.addImage(imgData, 'PNG', 10, position, imgWidth, imgHeight);
heightLeft -= (pdfHeight - 20);
while (heightLeft > 0) {
position = -heightLeft - 10;
pdf.addPage();
pdf.addImage(imgData, 'PNG', 10, position, imgWidth, imgHeight);
heightLeft -= (pdfHeight - 20);
}
pdf.save('My-Cardio-Fitness-Report.pdf');
})
.catch(err => console.error("PDF Generation Error:", err));
};
// --- START THE APP ---
initialize();
});
$1
') .replace(/\n\n/g, '') .replace(/\n- /g, '
- ') .replace(/(\n- .*?)+/g, (match) => match.replace(/\n- /g, '
- ') + '
