Spaces:
Running
Running
| """Report export: Markdown and PDF.""" | |
| import tempfile | |
| import time | |
| from pathlib import Path | |
| from markdown_pdf import MarkdownPdf, Section | |
| from code_tribunal.ui.helpers import evidence_html | |
| def export_md(ctx: dict) -> str: | |
| """Export trial context as a Markdown file. Returns the file path.""" | |
| md = [ | |
| "# CodeTribunal — Trial Report\n", | |
| f"**Generated**: {time.strftime('%Y-%m-%d %H:%M:%S')}\n", | |
| "---\n", | |
| ] | |
| for key in ["evidence", "verdict", "report"]: | |
| value = ctx.get(key, "") | |
| if value: | |
| md.append(f"## {key.title()}\n\n{value}\n\n") | |
| fp = tempfile.mktemp(suffix="_CodeTribunal_Report.md") | |
| Path(fp).write_text("\n".join(md)) | |
| return fp | |
| def export_pdf(ctx: dict) -> str: | |
| """Export trial context as a PDF file. Returns the file path.""" | |
| sections = [] | |
| for key in ["evidence", "verdict", "report"]: | |
| value = ctx.get(key, "") | |
| if value: | |
| sections.append(f"## {key.title()}\n\n{value}") | |
| full_md = ( | |
| f"# CodeTribunal - Trial Report\n\n" | |
| f"*Generated: {time.strftime('%Y-%m-%d %H:%M:%S')}*\n\n---\n\n" | |
| + "\n".join(sections) | |
| ) | |
| pdf = MarkdownPdf() | |
| pdf.add_section(Section(full_md)) | |
| fp = tempfile.mktemp(suffix="_CodeTribunal_Report.pdf") | |
| pdf.save(fp) | |
| return fp | |