"""HTML rendering helpers for the Gradio UI.""" from pathlib import Path from code_tribunal.ui.styles import SEVERITY_COLORS def escape_html(text: str) -> str: return text.replace("&", "&").replace("<", "<").replace(">", ">") def severity_badge(severity: str) -> str: color = SEVERITY_COLORS.get(severity, "#6b7280") return ( f'{severity}' ) def evidence_html(report) -> str: """Render an EvidenceReport as an HTML table.""" lines = [ "

Evidence Report

", f"

Files: {report.file_count} | Findings: {len(report.findings)}

", ] for domain, findings in report.findings_by_domain.items(): lines.append(f"

{domain.title()} ({len(findings)})

") lines.append('') lines.append( '' "" "" "" "" ) for finding in findings: lines.append( f'' f"" f"" f"" f"" ) lines.append("
SevFileLineCode
{severity_badge(finding.severity_hint)}" f"{Path(finding.file).name}{finding.line}" f"{escape_html(finding.code)}
") return "\n".join(lines)