feat(render-mode): Rich (LibreOffice) vs Standard (pandoc) toggle for office formats (.docx/.odt/.rtf); Rich default; 5 office tests; 152/152 green"
Test / Tests (Python 3.12) (push) Canceled after 0s

This commit is contained in:
Amelia
2026-09-04 17:31:26 -04:00
parent 383635c57c
commit 069dab0411
7 changed files with 318 additions and 13 deletions
+18 -2
View File
@@ -53,6 +53,10 @@ _ROUTING: dict[str, str] = {
}
# .epub is supported (existing pipeline) but routes differently.
# Office trio: the ONLY family gated by render_mode (rich->LibreOffice,
# standard->pandoc). All other extensions route via _ROUTING unchanged.
_OFFICE_EXTS = frozenset({".docx", ".odt", ".rtf"})
SUPPORTED_EXTENSIONS = frozenset(_ROUTING) | {".epub"}
@@ -68,13 +72,18 @@ def is_supported(filename: str) -> bool:
def convert_file(path: Path, job_id: str, progress_cb=None, output_dir=None,
source_name=None) -> str:
source_name=None, render_mode="rich") -> str:
"""Convert `path` to a PDF; return the output file name (no dir).
`source_name` is the original upload/CLI file name — the on-disk name
for web uploads is `{job_id}<ext>`, so the export name must be derived
from the original name, not the temp path.
`render_mode` ("rich" default | "standard") gates ONLY the office trio
(.docx/.odt/.rtf): rich -> LibreOffice, standard -> pandoc. Every other
extension (incl. .tex/.latex/.org/.adoc/.rst, which stay pandoc-only) and
.epub route exactly as before. An omitted/invalid render_mode is "rich".
Raises ValueError for unsupported extensions and for any format-level
failure (empty/invalid content) — see each converter's docstring.
"""
@@ -89,7 +98,14 @@ def convert_file(path: Path, job_id: str, progress_cb=None, output_dir=None,
return app.convert_epub(path, job_id, progress_cb=progress_cb,
output_dir=output_dir, source_name=source_name)
module_name = _ROUTING[ext]
# AC (matrix HAPPY_PATH_STANDARD / HAPPY_PATH_RICH): the office trio is the
# only family gated by render_mode. rich -> LibreOffice, standard -> pandoc.
# .tex/.latex/.org/.adoc/.rst stay pandoc-only (the pandoc module itself
# gates tex via \documentclass); every other extension routes as before.
if ext in _OFFICE_EXTS:
module_name = "office_converter" if render_mode == "rich" else "pandoc_converter"
else:
module_name = _ROUTING[ext]
module = __import__(f"converters.{module_name}", fromlist=["convert"])
return module.convert(Path(path), job_id, progress_cb=progress_cb,
output_dir=output_dir, source_name=source_name)