"""Office / LaTeX / structured-text formats -> PDF via Pandoc (Phase 2, Chunk A). Formats: .docx .odt .rtf .tex .latex .org .adoc .rst Pipeline: 1. Gate: can_handle() — docx/odt/rtf match on magic MIME (extension when no MIME is supplied); tex/latex/org/adoc/rst match on extension. .tex/.latex additionally require the text to contain \\documentclass or open with a % comment; anything else falls through to the generic plain-text converter (raw source rendered as monospace
).
2. Guard: docx/odt are zip containers — the same zip-slip + zip-bomb checks
as the EPUB path (app._safe_extract_zip) run against the member listing
BEFORE pandoc ever touches the file.
3. Title: docx -> docProps/core.xml ; odt -> meta.xml
; else the first in the generated HTML; else the file
stem (the naming fallback in common.derive_export_name).
4. Pandoc: `pandoc -f -t html5 --standalone --embed-resources
[--metadata title=] -o ` with capture_output and a 600 s
timeout. Non-zero exit -> ValueError with a concise user-safe message;
stderr is logged at DEBUG only.
5. Sanitize: ",
re.IGNORECASE | re.DOTALL)
_SCRIPT_TAG_RE = re.compile(r"