vscode修改题目内容中增加对备注的修改功能

This commit is contained in:
wangweiye7840 2023-06-28 13:02:13 +08:00
parent 67b81c66a9
commit 9600c10cb0
1 changed files with 11 additions and 8 deletions

View File

@ -509,30 +509,32 @@ def GenerateTexDataforEditing(id_string,prodict,templatefilepath,editor): # 根
content = prodict[id]["content"]
answer = prodict[id]["ans"]
solution = prodict[id]["solution"]
output += "\\item (%s) "%str(id).zfill(6) + content + "\n\n" + "答案: " + answer + "\n\n" + "解答与提示: " + solution + "\n\n"
remark = prodict[id]["remark"]
output += "\\item (%s) "%str(id).zfill(6) + content + "\n\n" + "答案: " + answer + "\n\n" + "解答与提示: " + solution + "\n\n" + "备注: " + remark + "\n\n"
output += "\\end{enumerate}"
template = ReadTextFile(templatefilepath)
texdata = StringSubstitute(r"<<[\s\S]*?>>",template,[output])
return texdata # 返回Tex文件的字符串, 待保存至tex文件
def GetEditedProblems(string): #从.tex文件所读取的字符串中取出正文内容, 并切割成以题号为key的字典, 内容为[题目内容, 答案, 解答与提示]三元数组
def GetEditedProblems(string): #从.tex文件所读取的字符串中取出正文内容, 并切割成以题号为key的字典, 内容为[题目内容, 答案, 解答与提示, 备注]四元数组
bodydata = re.findall(r"\\begin\{enumerate\}([\s\S]*)\\end\{enumerate\}",string)[0]+r"\item"
problems = re.findall(r"\((\d{6})\)([\s\S]*?)\\item",bodydata)
edited_dict = {}
for problem in problems:
id, pro_string = problem
edited_dict[id] = parseProblem(pro_string)
return edited_dict # 返回以题号为key, 内容为[题目内容, 答案, 解答与提示]三元数组的字典
return edited_dict # 返回以题号为key, 内容为[题目内容, 答案, 解答与提示, 备注]四元数组的字典
def parseProblem(string): # 对以不小于两个回车切分的段式字符串进行分词(通常第二段有"答案:", 第三段有"解答与提示:")
def parseProblem(string): # 对以不小于两个回车切分的段式字符串进行分词(通常第二段有"答案:", 第三段有"解答与提示:", 第四段有"备注:")
data = string.strip()
data = re.sub(r"\n{2,}","\n\n",data)
content,ans,solution = data.split("\n\n")
content,ans,solution,remark = data.split("\n\n")
content = content.strip()
ans = re.sub("答案:","",ans).strip()
solution = re.sub("解答与提示:","",solution).strip()
return (content,ans,solution) # 返回三元组(题目内容, 答案, 解答与提示)
remark = re.sub("备注:","",remark).strip()
return (content,ans,solution,remark) # 返回四元组(题目内容, 答案, 解答与提示, 备注)
def ModifyProblembyTeX(id_string,prodict,toeditfilepath,editor): # vscode打开.tex文件修改题目的内容, 答案与解答
@ -552,11 +554,12 @@ def ModifyProblembyTeX(id_string,prodict,toeditfilepath,editor): # vscode打开.
# 将.tex文件中的修改反映到原题库字典, 并保存
for id in edited_dict:
content, ans, solution = edited_dict[id]
if not (content == prodict[id]["content"] and ans == prodict[id]["ans"] and solution == prodict[id]["solution"]):
content, ans, solution, remark = edited_dict[id]
if not (content == prodict[id]["content"] and ans == prodict[id]["ans"] and solution == prodict[id]["solution"] and remark == prodict[id]["remark"]):
prodict[id]["content"] = content
prodict[id]["ans"] = ans
prodict[id]["solution"] = solution
prodict[id]["remark"] = remark
prodict[id]["edit"] = prodict[id]["edit"] + [editor]
editedIDList.append(id)