53 lines
1.5 KiB
Python
53 lines
1.5 KiB
Python
|
|
#!/usr/bin/env python
|
|||
|
|
# -*- coding: utf-8 -*-
|
|||
|
|
"""
|
|||
|
|
合并1.md到6.md文件,在合并处添加分隔标注
|
|||
|
|
"""
|
|||
|
|
|
|||
|
|
import re
|
|||
|
|
|
|||
|
|
def remove_line_numbers(content):
|
|||
|
|
"""移除每行开头的行号格式(如 ' 1→')"""
|
|||
|
|
lines = content.split('\n')
|
|||
|
|
cleaned_lines = []
|
|||
|
|
for line in lines:
|
|||
|
|
# 匹配并移除行号格式:空格+数字+→
|
|||
|
|
cleaned = re.sub(r'^\s*\d+→', '', line)
|
|||
|
|
cleaned_lines.append(cleaned)
|
|||
|
|
return '\n'.join(cleaned_lines)
|
|||
|
|
|
|||
|
|
def main():
|
|||
|
|
output_lines = []
|
|||
|
|
|
|||
|
|
for i in range(1, 7):
|
|||
|
|
filename = f"{i}.md"
|
|||
|
|
|
|||
|
|
try:
|
|||
|
|
with open(filename, 'r', encoding='utf-8') as f:
|
|||
|
|
content = f.read()
|
|||
|
|
|
|||
|
|
# 移除行号
|
|||
|
|
cleaned_content = remove_line_numbers(content)
|
|||
|
|
|
|||
|
|
# 添加分隔标注(第一个文件不需要)
|
|||
|
|
if i > 1:
|
|||
|
|
separator = "\n\n---\n\n**【以下为下一页,发言者的区分将重记】**\n\n---\n\n"
|
|||
|
|
output_lines.append(separator)
|
|||
|
|
|
|||
|
|
output_lines.append(cleaned_content)
|
|||
|
|
print(f"已处理: {filename}")
|
|||
|
|
|
|||
|
|
except FileNotFoundError:
|
|||
|
|
print(f"文件不存在: {filename}")
|
|||
|
|
return
|
|||
|
|
|
|||
|
|
# 写入合并后的文件
|
|||
|
|
output_filename = "会议转写_合并版.md"
|
|||
|
|
with open(output_filename, 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(''.join(output_lines))
|
|||
|
|
|
|||
|
|
print(f"\n合并完成!输出文件: {output_filename}")
|
|||
|
|
|
|||
|
|
if __name__ == "__main__":
|
|||
|
|
main()
|