浏览代码

渲染填空题类型cloze

Michael Wang 3 年之前
父节点
当前提交
1f320b459e
共有 1 个文件被更改,包括 5 次插入0 次删除
  1. 5 0
      src/utils/renderJSON.ts

+ 5 - 0
src/utils/renderJSON.ts

@@ -3,6 +3,7 @@
 import { RichTextBlockJSON, RichTextJSON, RichTextSectionJSON } from "@/types";
 import { RichTextBlockJSON, RichTextJSON, RichTextSectionJSON } from "@/types";
 
 
 let _container = document.createElement("div");
 let _container = document.createElement("div");
+let clozeIndex = 0;
 /**
 /**
  * 将富文本 JSON 渲染到指定的元素中
  * 将富文本 JSON 渲染到指定的元素中
  *
  *
@@ -11,6 +12,7 @@ let _container = document.createElement("div");
  */
  */
 export function renderRichText(body: RichTextJSON, container?: HTMLDivElement) {
 export function renderRichText(body: RichTextJSON, container?: HTMLDivElement) {
   _container = container || document.createElement("div");
   _container = container || document.createElement("div");
+  clozeIndex = 0;
   let sections = body?.sections || [];
   let sections = body?.sections || [];
   let nodes = [] as Array<Node>;
   let nodes = [] as Array<Node>;
   sections.forEach((section) => {
   sections.forEach((section) => {
@@ -117,6 +119,9 @@ function renderBlock(block: RichTextBlockJSON, inline: boolean) {
     node.className = "audio";
     node.className = "audio";
     node.src = block.value;
     node.src = block.value;
     node.controls = true;
     node.controls = true;
+  } else if (block.type === "cloze") {
+    node = document.createElement("span");
+    node.innerHTML = `___${++clozeIndex}___`;
   }
   }
 
 
   return node as Node;
   return node as Node;