Files
redmine-reporter/redmine_reporter/formatters/markdown.py
Кокос Артем Николаевич 2db0ab1f0b Tighten configuration and export handling
2026-05-22 17:41:56 +07:00

37 lines
1.3 KiB
Python

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", "<br>")
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)