Spaces:
Running
Running
File size: 1,959 Bytes
ca2b985 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | """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'<span style="background:{color};color:white;padding:2px 8px;'
f'border-radius:4px;font-size:12px;font-weight:bold">{severity}</span>'
)
def evidence_html(report) -> str:
"""Render an EvidenceReport as an HTML table."""
lines = [
"<h3>Evidence Report</h3>",
f"<p>Files: <b>{report.file_count}</b> | Findings: <b>{len(report.findings)}</b></p>",
]
for domain, findings in report.findings_by_domain.items():
lines.append(f"<h4>{domain.title()} ({len(findings)})</h4>")
lines.append('<table style="width:100%;border-collapse:collapse">')
lines.append(
'<tr style="border-bottom:1px solid #333">'
"<th style='text-align:left;padding:4px'>Sev</th>"
"<th style='text-align:left;padding:4px'>File</th>"
"<th style='text-align:left;padding:4px'>Line</th>"
"<th style='text-align:left;padding:4px'>Code</th></tr>"
)
for finding in findings:
lines.append(
f'<tr style="border-bottom:1px solid #222">'
f"<td style='padding:4px'>{severity_badge(finding.severity_hint)}</td>"
f"<td style='padding:4px;font-family:monospace;font-size:13px'>"
f"{Path(finding.file).name}</td>"
f"<td style='padding:4px;font-family:monospace'>{finding.line}</td>"
f"<td style='padding:4px;font-family:monospace;font-size:13px;color:#a0a0a0'>"
f"{escape_html(finding.code)}</td></tr>"
)
lines.append("</table>")
return "\n".join(lines)
|