// ESM module: shared printable HTML builder // Note: callers must sanitize any HTML fields (e.g., summary) before passing. function escapeText(str) { if (str == null) return ''; return String(str) .replace(/&/g, '&') .replace(//g, '>') .replace(/\"/g, '"') .replace(/'/g, '''); } export function buildPrintableHtml(cv) { const { personal = {}, summary = '', work = [], education = [], skills = [], languages = [], certifications = [] } = cv || {}; const styles = ` `; const headerLinks = (personal.links || []) .map(l => `${escapeText(l.label || l.url)}`) .join(' · '); const headerHtml = `

${escapeText(personal.firstName || '')} ${escapeText(personal.lastName || '')}

${personal.email ? `${escapeText(personal.email)}` : ''} ${personal.phone ? `${escapeText(personal.phone)}` : ''} ${(personal.city || personal.country) ? `${personal.city ? escapeText(personal.city) : ''}${personal.city && personal.country ? ', ' : ''}${personal.country ? escapeText(personal.country) : ''}` : ''} ${headerLinks ? `${headerLinks}` : ''}
`; const summarySection = summary ? `

Professional Summary

${summary}
` : ''; const workSection = (work && work.length) ? `

Work Experience

${work.map(job => `

${escapeText(job.title)}

${escapeText(job.company)}
${escapeText(job.startDate || '')} - ${escapeText(job.endDate || 'Present')} ${job.location ? `
${escapeText(job.location)}
` : ''}
${(job.bullets && job.bullets.length) ? ` ` : ''}
`).join('')}
` : ''; const eduSection = (education && education.length) ? `

Education

${education.map(ed => `

${escapeText(ed.degree)}

${escapeText(ed.school)}
${escapeText(ed.startDate || '')} - ${escapeText(ed.endDate || '')}
${ed.gpa ? `
GPA: ${escapeText(ed.gpa)}
` : ''}
`).join('')}
` : ''; const skillsSection = (skills && skills.length) ? `

Skills

${skills.map(s => `${escapeText(s.name)}${s.level ? ` — ${escapeText(s.level)}` : ''}`).join('')}
` : ''; const languagesSection = (languages && languages.length) ? `

Languages

${languages.map(l => `${escapeText(l.name)}${l.level ? ` — ${escapeText(l.level)}` : ''}`).join('')}
` : ''; const certsSection = (certifications && certifications.length) ? `

Certifications

` : ''; return ` Printable CV ${styles}
${headerHtml} ${summarySection} ${workSection} ${eduSection} ${skillsSection} ${languagesSection} ${certsSection}
`; }