d4665a362e
- 新增 officefile/latex/ 目录,包含 main.tex、preamble.tex 及 14 个章节 + 10 个附录 tex 文件 - md→tex 转换流程:pandoc 转换 + _postprocess.py 后处理(去编号、修破折号、清标签) - 修复 5 个 md 源文件的标题层级(H1→H2 降级,统一层级结构) - 配置 VS Code LaTeX Workshop(xelatex + ctexbook 编译链) - 新增 VS Code workspace 和 .gitignore(排除 LaTeX 编译产物) Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
"""Fix H1 headings in md files: keep first # as chapter, demote rest to ##."""
|
|
import os
|
|
|
|
base = r'e:/Project/SI/2026_DesignAI/officefile'
|
|
|
|
files_to_fix = [
|
|
'01-introduction/01-introduction.md',
|
|
'03-1d-sequence/03-1d-sequence.md',
|
|
'05-3d-spatial/05-3d-spatial.md',
|
|
'08-reinforcement/08-reinforcement.md',
|
|
]
|
|
|
|
for rel_path in files_to_fix:
|
|
fpath = os.path.join(base, rel_path)
|
|
with open(fpath, 'r', encoding='utf-8') as f:
|
|
lines = f.readlines()
|
|
|
|
seen_first_h1 = False
|
|
changes = 0
|
|
in_code_block = False
|
|
|
|
for i, line in enumerate(lines):
|
|
# Track fenced code blocks
|
|
if line.startswith('```'):
|
|
in_code_block = not in_code_block
|
|
continue
|
|
|
|
if in_code_block:
|
|
continue
|
|
|
|
# Only target H1 headings (start with "# " but not "## ")
|
|
if line.startswith('# ') and not line.startswith('## '):
|
|
if not seen_first_h1:
|
|
seen_first_h1 = True
|
|
continue # Keep the first H1 as chapter title
|
|
|
|
# Demote: "# heading" -> "## heading"
|
|
lines[i] = '#' + line # "# " -> "## "
|
|
changes += 1
|
|
|
|
with open(fpath, 'w', encoding='utf-8') as f:
|
|
f.writelines(lines)
|
|
|
|
print(f'{rel_path}: demoted {changes} H1 -> H2 (kept first as chapter)')
|