File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 1+ import os
2+ import subprocess
3+ import shutil
4+
5+ def markdown_to_pdf (directory ):
6+ # 检查 Pandoc 是否可用
7+ if not shutil .which ("pandoc" ):
8+ raise FileNotFoundError ("Pandoc 未安装或未在 PATH 中找到。" )
9+
10+ # 获取目录下的所有 Markdown 文件(递归)
11+ markdown_files = []
12+ for root , _ , files in os .walk (directory ):
13+ for file in files :
14+ if file .endswith ('.md' ):
15+ markdown_files .append (os .path .join (root , file ))
16+
17+ # 排序文件(可选)
18+ markdown_files .sort ()
19+
20+ # 创建临时的合并 Markdown 文件
21+ temp_md_file = os .path .join (directory , 'merged.md' )
22+
23+ with open (temp_md_file , 'w' , encoding = 'utf-8' ) as outfile :
24+ for md_file in markdown_files :
25+ with open (md_file , 'r' , encoding = 'utf-8' ) as infile :
26+ outfile .write (infile .read () + '\n \n ' )
27+
28+ markdown_to_pdf (directory = "./docs/notes/zh" )
You can’t perform that action at this time.
0 commit comments