from typing import List from ..types import ReportRow from .base import Formatter def _escape_markdown_table_cell(value: object) -> str: return str(value).replace("\\", "\\\\").replace("|", "\\|").replace("\n", "
") class MarkdownFormatter(Formatter): """Форматтер для экспорта в Markdown.""" def __init__(self, **_kwargs): super().__init__() def format(self, rows: List[ReportRow]) -> str: lines = [ "| Проект | Версия | Задача | Статус | Затрачено |", "|--------|--------|--------|--------|-----------|", ] for r in rows: task_cell = _escape_markdown_table_cell(f"{r['issue_id']}. {r['subject']}") lines.append( f"| {_escape_markdown_table_cell(r['display_project'])} " f"| {_escape_markdown_table_cell(r['display_version'])} " f"| {task_cell} " f"| {_escape_markdown_table_cell(r['status_ru'])} " f"| {_escape_markdown_table_cell(r['time_text'])} |" ) return "\n".join(lines) def save(self, rows: List[ReportRow], output_path: str) -> None: content = self.format(rows) with open(output_path, "w", encoding="utf-8") as f: f.write(content)