fix(exam): 改进多选题答案换行逻辑,避免误分割内容
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -1184,10 +1184,15 @@ const formatCorrectAnswer = (question: any) => {
|
|||||||
if (question.type === 'single' || question.type === 'multiple') {
|
if (question.type === 'single' || question.type === 'multiple') {
|
||||||
// 如果有correctAnswer字段(来自Dify的原始correct)
|
// 如果有correctAnswer字段(来自Dify的原始correct)
|
||||||
if (question.correctAnswer) {
|
if (question.correctAnswer) {
|
||||||
// 多选题格式优化:将 "A:xxx,B:xxx" 改为换行显示
|
// 多选题格式优化:将 "A:xxx、B:xxx" 或 "A:xxx,B:xxx" 改为换行显示
|
||||||
// 匹配 ",A:" 或 ",B:" 等格式,在逗号后的选项字母前换行
|
// 使用更精确的匹配:提取完整的选项格式 X:内容
|
||||||
const formatted = question.correctAnswer.replace(/,([A-Za-z][::])/g, '\n$1')
|
const optionPattern = /([A-Za-z][::])([^A-Za-z]*?)(?=(?:[,、]?[A-Za-z][::])|$)/g
|
||||||
return formatted
|
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中提取
|
// 否则从options中提取
|
||||||
return question.options
|
return question.options
|
||||||
|
|||||||
Reference in New Issue
Block a user