Pythonで指定したmdファイルを読み込んで、マージしたファイルを生成する
code:margefile.py
import re
import os
indexfilePath = "index.list"
outputPath = "body.md"
tempbody = []
with open(indexfilePath) as f:
l = f.readlines()
for line in l:
m = re.search(r"\[\(.*)\\]",line) if m and os.path.isfile(m.group(1)):
with open(m.group(1)) as f:
tempbody.extend(f.readlines())
else:
tempbody.append(line)
with open(outputPath,mode="w") as f:
f.writelines(tempbody)
code:index.list
% 『ライフハックの道具箱2022』
% 倉下忠憲編著
010_1.md
010_2.md
sample.md
ここに並べた順番で統合される
ファイル名を連番にする必要がなくなる