"""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 = ['| {escape(c)} | ') h.append('
|---|
| {escape(str(r.get(c, "")))} | ') h.append('