diff --git a/src/modules/exams/actions.ts b/src/modules/exams/actions.ts index b422e22..69e3391 100644 --- a/src/modules/exams/actions.ts +++ b/src/modules/exams/actions.ts @@ -1137,17 +1137,28 @@ const buildTiptapDocFromAiResponse = (data: unknown): unknown => { }) } - // 子题(阅读理解的小题) + // 子题(阅读理解的小题)—— 生成为嵌套的 questionBlock,便于编辑器层级展示与解析 const subQuestions = Array.isArray(contentNode.subQuestions) ? contentNode.subQuestions : [] for (const sub of subQuestions) { if (!isRecord(sub)) continue const subText = typeof sub.text === "string" ? sub.text : "" + const subScore = typeof sub.score === "number" ? sub.score : 0 if (subText) { + // 子题文本按行拆分为段落 + const subLines = subText.split("\n").filter((l) => l.trim().length > 0) + const subInner = + subLines.length > 0 + ? subLines.map((line) => ({ + type: "paragraph", + content: [{ type: "text", text: line }], + })) + : [{ type: "paragraph", content: [{ type: "text", text: " " }] }] inner.push({ - type: "paragraph", - content: [{ type: "text", text: subText }], + type: "questionBlock", + attrs: { questionId: "", type: "text", score: subScore }, + content: subInner, }) } } diff --git a/src/modules/exams/components/exam-rich-form.tsx b/src/modules/exams/components/exam-rich-form.tsx index 7972e29..fccbd29 100644 --- a/src/modules/exams/components/exam-rich-form.tsx +++ b/src/modules/exams/components/exam-rich-form.tsx @@ -329,16 +329,16 @@ function ExamPreview({ structure }: { structure: EditorDoc }) { ): React.ReactNode => { if (node.type === "group") { return ( -
+ 暂无题目,请在左侧编辑器中添加 +
+ ) : ( + structure.structure.map((node) => renderNode(node)) + )}