""" Export reports to PDF and Markdown. M7 — Extras. """ from pathlib import Path from typing import Any def report_to_markdown(report: dict[str, Any]) -> str: """Convert report dict to Markdown string.""" from .inference import format_report_markdown return format_report_markdown(report) def export_markdown(report: dict[str, Any], path: str | Path) -> Path: """Export report to Markdown file.""" path = Path(path) path.parent.mkdir(parents=True, exist_ok=True) md = report_to_markdown(report) path.write_text(md, encoding="utf-8") return path def export_html(report: dict[str, Any], path: str | Path) -> Path: """Export report to HTML file (print-friendly, convertible to PDF via browser).""" try: import markdown except ImportError: raise ImportError("Install markdown: pip install markdown") from None path = Path(path) path.parent.mkdir(parents=True, exist_ok=True) md = report_to_markdown(report) html_content = markdown.markdown(md, extensions=["tables"]) full_html = f""" Cyber Report {html_content}""" path.write_text(full_html, encoding="utf-8") return path