"""Generic CSV table renderer. Used for all CSV @import unless overridden.""" import csv from html import escape def render(filepath): """Load CSV and render as HTML table.""" rows = [] with open(str(filepath), encoding='utf-8') as f: for row in csv.DictReader(f): rows.append({ k.strip(): v.strip() if v else '' for k, v in row.items() }) if not rows: return '

empty file

' cols = list(rows[0].keys()) h = [''] for c in cols: h.append(f'') h.append('') for r in rows: h.append('') for c in cols: h.append(f'') h.append('') h.append('
{escape(c)}
{escape(str(r.get(c, "")))}
') return '\n'.join(h)