_gen_deploy_docx.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # -*- coding: utf-8 -*-
  2. """把系统初始化配置指南 Markdown 转成 Word。
  3. 排版逻辑不在这里重复一遍,直接复用系统集成那套生成器:横向版式、黑体标题套内置
  4. Heading 样式(Word 导航窗格与自动目录才认得层级)、表格 Table Grid 加表头底色、
  5. 一级标题前分页、「目录」一节换成 Word 自动目录域。
  6. """
  7. from __future__ import annotations
  8. import importlib.util
  9. import sys
  10. from pathlib import Path
  11. BASE = Path(__file__).resolve().parent
  12. GENERATOR = BASE.parent / "系统集成" / "_gen_integration_guide_docx.py"
  13. JOBS = [
  14. ("Ai-DOP系统初始化配置指南.md", "Ai-DOP系统初始化配置指南.docx", True, True),
  15. ]
  16. def load_generator():
  17. spec = importlib.util.spec_from_file_location("_aidop_docx_generator", GENERATOR)
  18. if spec is None or spec.loader is None:
  19. raise SystemExit(f"找不到排版生成器:{GENERATOR}")
  20. module = importlib.util.module_from_spec(spec)
  21. sys.modules[spec.name] = module
  22. spec.loader.exec_module(module)
  23. return module
  24. def main():
  25. gen = load_generator()
  26. for src_name, out_name, landscape, page_break_before_h1 in JOBS:
  27. src = BASE / src_name
  28. out = BASE / out_name
  29. doc = gen.build_docx(src.read_text(encoding="utf-8"), landscape, page_break_before_h1)
  30. doc.save(out)
  31. print(f"OK: {out}")
  32. if __name__ == "__main__":
  33. main()