[UPDATE] рефакторинг: handlers, fontspec, Docker optimization
This commit is contained in:
+23
-8
@@ -7,6 +7,16 @@ from md2gost.parser import Parser
|
||||
from md2gost.render import Renderer
|
||||
|
||||
|
||||
def run_xelatex(tex_path: Path, output_dir: Path) -> bool:
|
||||
result = subprocess.run(
|
||||
["xelatex", "-interaction=nonstopmode",
|
||||
"-output-directory", str(output_dir), str(tex_path)],
|
||||
capture_output=True, text=True,
|
||||
)
|
||||
pdf_path = output_dir / tex_path.with_suffix(".pdf").name
|
||||
return pdf_path.exists()
|
||||
|
||||
|
||||
def main():
|
||||
cli = argparse.ArgumentParser(
|
||||
prog="md2gost",
|
||||
@@ -40,16 +50,21 @@ def main():
|
||||
|
||||
if not args.no_pdf:
|
||||
pdf_path = args.output / args.input.with_suffix(".pdf").name
|
||||
result = subprocess.run(
|
||||
["xelatex", "-interaction=nonstopmode", "-output-directory", str(args.output), str(tex_path)],
|
||||
capture_output=True, text=True,
|
||||
)
|
||||
if not pdf_path.exists():
|
||||
print(result.stdout[-2000:], file=sys.stderr)
|
||||
log_path = args.output / "report.log"
|
||||
|
||||
if not run_xelatex(tex_path, args.output):
|
||||
print("ошибка: xelatex не собрал PDF", file=sys.stderr)
|
||||
if log_path.exists():
|
||||
for line in log_path.read_text(errors="replace").splitlines():
|
||||
if line.startswith("!"):
|
||||
print(f" {line}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
if not run_xelatex(tex_path, args.output):
|
||||
print("ошибка: xelatex (2-й проход) не собрал PDF", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
print(f"→ {pdf_path}")
|
||||
if result.returncode != 0:
|
||||
print(" (предупреждения xelatex, PDF собран)", file=sys.stderr)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user