- fix Не появляется пустая странициа перед названием таблицы - fix Не появляется пустая страница перед альбомной ориентацией - fix При отказе от изменений создаётся новый файл - fix Замена "..." на «...» больше не затрагивает uml и mermaid блоки
This commit is contained in:
+27
-1
@@ -8,6 +8,7 @@ import platform
|
||||
import subprocess
|
||||
import traceback
|
||||
from dataclasses import dataclass
|
||||
from datetime import datetime
|
||||
from getpass import getuser
|
||||
from typing import Callable
|
||||
|
||||
@@ -73,6 +74,25 @@ def default_output_path(filename: str) -> str:
|
||||
return os.path.join(os.path.dirname(os.path.abspath(filename)), base + ".docx")
|
||||
|
||||
|
||||
def timestamped_output_path(path: str) -> str:
|
||||
"""report.docx → report_2026-09-05-10-05.docx (local time; seconds if taken)."""
|
||||
directory, name = os.path.split(os.path.abspath(path))
|
||||
stem, ext = os.path.splitext(name)
|
||||
if ext.lower() != ".docx":
|
||||
ext = ".docx"
|
||||
stamp = datetime.now().strftime("%Y-%m-%d-%H-%M")
|
||||
candidate = os.path.join(directory, f"{stem}_{stamp}{ext}")
|
||||
if not os.path.exists(candidate):
|
||||
return candidate
|
||||
stamp = datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
|
||||
candidate = os.path.join(directory, f"{stem}_{stamp}{ext}")
|
||||
n = 2
|
||||
while os.path.exists(candidate):
|
||||
candidate = os.path.join(directory, f"{stem}_{stamp}_{n}{ext}")
|
||||
n += 1
|
||||
return candidate
|
||||
|
||||
|
||||
def default_template_path() -> str:
|
||||
return os.path.join(package_dir(), "Template.docx")
|
||||
|
||||
@@ -235,7 +255,13 @@ def convert(req: ConvertRequest, log: LogFn | None = None) -> ConvertResult:
|
||||
|
||||
document.core_properties.author = getuser()
|
||||
document.core_properties.comments = "Создано при помощи md2gost (ТЗ МИРЭА)"
|
||||
document.save(output)
|
||||
try:
|
||||
document.save(output)
|
||||
except PermissionError:
|
||||
alt = timestamped_output_path(output)
|
||||
emit(f"Не удалось записать {output} (файл занят). Сохраняю как {alt}")
|
||||
document.save(alt)
|
||||
output = alt
|
||||
except Exception as exc:
|
||||
emit(traceback.format_exc())
|
||||
return ConvertResult(
|
||||
|
||||
Reference in New Issue
Block a user