Files
md_to_gost/md2gost/office/dispatch.py
T
Igor20264 daa84f8bce
Example document / build (push) Has been cancelled
Python application / build (push) Has been cancelled
v0.5.6
2026-09-22 18:49:09 +03:00

60 lines
1.9 KiB
Python

"""Route table/listing continuation post-processing to Word or UNO backends."""
from __future__ import annotations
from ..word_fix import FixResult, fix_continuations
from .detect import DEFAULT_OFFICE_ENGINE, resolve_office_engine
from .uno_fix import fix_continuations_uno
def fix_continuations_with_engine(
path: str,
*,
engine: str = DEFAULT_OFFICE_ENGINE,
tables: bool = True,
listings: bool = True,
repeat_header: bool = False,
) -> FixResult:
"""
Split cross-page tables/listings using the selected office engine.
``engine`` is ``auto|word|libre|openoffice``. On missing backend returns
``ok=False`` with a reason; conversion should continue.
"""
resolved, install = resolve_office_engine(engine)
if resolved is None or install is None:
if engine == "auto":
return FixResult(
False,
message=(
"Пост-разрыв таблиц пропущен: не найден Word, LibreOffice "
"или OpenOffice."
),
)
labels = {
"word": "Microsoft Word (Windows + pywin32)",
"libre": "LibreOffice (soffice + program/python)",
"openoffice": "OpenOffice (soffice + program/python)",
}
return FixResult(
False,
message=f"Пост-разрыв таблиц пропущен: нужен {labels.get(engine, engine)}.",
)
if resolved == "word":
return fix_continuations(
path,
tables=tables,
listings=listings,
repeat_header=repeat_header,
)
assert install.soffice_path and install.python_path
return fix_continuations_uno(
path,
install=install,
tables=tables,
listings=listings,
repeat_header=repeat_header,
)