Blame view

scripts/spec-docx/build.sh 1.31 KB
866afeed   王彪总   1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
  #!/usr/bin/env bash
  # 由 Markdown 源文件生成《下级平台数据接入规范》Word 文档。
  # 依赖:pandoc、unzip、zip、python3(不需要 Word / LibreOffice)。
  #
  #   ./scripts/spec-docx/build.sh
  #
  # 改内容只改 docs/*.md,然后重跑本脚本即可。
  set -euo pipefail
  
  SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
  NAME="赤峰市智慧停车管理平台-下级平台数据接入规范-v1.1"
  MD="$ROOT/docs/$NAME.md"
  OUT="$ROOT/docs/$NAME.docx"
  
  [ -f "$MD" ] || { echo "找不到源文件: $MD" >&2; exit 1; }
  
  WORK="$(mktemp -d)"
  trap 'rm -rf "$WORK"' EXIT
  
  # 1. 取出 pandoc 默认参考样式,改成中文政企文档样式
  pandoc --print-default-data-file reference.docx > "$WORK/ref.docx"
  unzip -q "$WORK/ref.docx" -d "$WORK/ref"
  python3 -I "$SCRIPT_DIR/patch-styles.py" "$WORK/ref/word/styles.xml"
  ( cd "$WORK/ref" && zip -q -X -r "$WORK/ref-cn.docx" . )
  
  # 2. Markdown → docx(不启用 --toc:目录由后处理插到红头标题之后)
  pandoc "$MD" -f markdown -t docx \
    --reference-doc="$WORK/ref-cn.docx" \
    -o "$WORK/raw.docx"
  
  # 3. 后处理:公文页面设置、目录域、页脚页码、分页、表格列宽与边框、文档属性
  unzip -q "$WORK/raw.docx" -d "$WORK/out"
  python3 -I "$SCRIPT_DIR/postprocess.py" "$WORK/out" "$OUT"