fix(exam): 改进多选题答案换行逻辑,避免误分割内容
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
yuliang_guo
2026-01-28 14:40:49 +08:00
parent 973023c1d8
commit fc299ed7b7

View File

@@ -1184,10 +1184,15 @@ const formatCorrectAnswer = (question: any) => {
if (question.type === 'single' || question.type === 'multiple') {
// 如果有correctAnswer字段来自Dify的原始correct
if (question.correctAnswer) {
// 多选题格式优化:将 "Axxx,Bxxx" 改为换行显示
// 匹配 ",A" 或 ",B" 等格式,在逗号后的选项字母前换行
const formatted = question.correctAnswer.replace(/,([A-Za-z][:])/g, '\n$1')
return formatted
// 多选题格式优化:将 "Axxx、Bxxx" 或 "Axxx,Bxxx" 改为换行显示
// 使用更精确的匹配:提取完整的选项格式 X内容
const optionPattern = /([A-Za-z][:])([^A-Za-z]*?)(?=(?:[,、]?[A-Za-z][:])|$)/g
const matches = [...question.correctAnswer.matchAll(optionPattern)]
if (matches.length > 1) {
// 多个选项,换行显示
return matches.map(m => m[1] + m[2].trim()).join('\n')
}
return question.correctAnswer
}
// 否则从options中提取
return question.options