|
@@ -13,8 +13,8 @@ let clozeIndex = 0;
|
|
|
export function renderRichText(body: RichTextJSON, container?: HTMLDivElement) {
|
|
|
_container = container || document.createElement("div");
|
|
|
clozeIndex = 0;
|
|
|
- let sections = body?.sections || [];
|
|
|
- let nodes = [] as Array<Node>;
|
|
|
+ const sections = body?.sections || [];
|
|
|
+ const nodes = [] as Array<Node>;
|
|
|
sections.forEach((section) => {
|
|
|
nodes.push(renderSection(section));
|
|
|
});
|
|
@@ -36,9 +36,9 @@ export function renderRichText(body: RichTextJSON, container?: HTMLDivElement) {
|
|
|
* @returns {HTMLDivElement} 返回根据 section 渲染好的 HTMLDivElement
|
|
|
*/
|
|
|
function renderSection(section: RichTextSectionJSON) {
|
|
|
- let blocks = section.blocks || [];
|
|
|
- let inline = blocks.length > 1;
|
|
|
- let node = document.createElement("div");
|
|
|
+ const blocks = section.blocks || [];
|
|
|
+ const inline = blocks.length > 1;
|
|
|
+ const node = document.createElement("div");
|
|
|
// node.style = "display: flex;";
|
|
|
blocks.forEach((block) => {
|
|
|
node.appendChild(renderBlock(block, inline));
|