import re with open('src/views/ExamWorkshop.vue', 'r', encoding='utf-8') as f: content = f.read() pattern = re.compile(r'(\s*
)(.*?)(^\s*)', re.DOTALL | re.MULTILINE) new_content = """
<-5 中间主要工作区 -->
<-5 试卷名称 -->
{{ examName?.length || 0 }}/32
<-5 出题依据内容 -->
<-5 从PPT生成考题 -->
cloud_upload

从PPT生成考题

上传培训PPT,智能提取关键内容生成考题(单个文件可上传20M内)

已上传: {{ selectedFile.name }} ×
chevron_right
<-5 题型配置 -->
题型配置
试卷总分
{{ calculatedTotalScore }}
{{ type.name }} 每题 {{ type.scorePerQuestion }} 分
数量 {{ type.questionCount }}
<-5 底部悬浮操作栏 -->
<-5 右侧边栏 (实时预览) -->
""" replaced = pattern.sub(r'\1\n' + new_content + r'\n\3', content) # 隐藏原来的 work-header 并修改 work-content 的样式 replaced = replaced.replace('
', '
') replaced = replaced.replace('
', '
') with open('src/views/ExamWorkshop.vue', 'w', encoding='utf-8') as f: f.write(replaced) print("Replacement complete.")