// 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 = `
`;
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) ? `
${job.bullets.map(b => `- ${escapeText(b)}
`).join('')}
` : ''}
`).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
${certifications.map(c => `- ${escapeText(c.name)}${c.issuer ? ` - ${escapeText(c.issuer)}` : ''}${c.date ? ` (${escapeText(c.date)})` : ''}
`).join('')}
` : '';
return `
Printable CV
${styles}
${headerHtml}
${summarySection}
${workSection}
${eduSection}
${skillsSection}
${languagesSection}
${certsSection}
`;
}