"""HTML / HTM -> PDF. A standalone .html upload is rendered as-is: the document's own " m = re.search(r"]*>", html_text, re.IGNORECASE) if m: return html_text[: m.end()] + style + html_text[m.end():] return style + html_text def convert(path: Path, job_id: str, progress_cb=None, output_dir=None, source_name=None) -> str: """Render a standalone HTML/HTM file to a typeset PDF.""" raw = path.read_bytes() html_text = common.decode_declared(raw) if not html_text.strip(): raise ValueError("empty file: nothing to convert") title = _extract_title(html_text) def _build(): return _inject_base_css(html_text), path.name return common.convert_single( path, job_id, build_html=_build, title=title, css="", progress_cb=progress_cb, output_dir=output_dir, name_src=source_name or path.name, )