diff --git a/src/service/print/docx.js b/src/service/print/docx.js index 98dc128a1773d99c0111f266f0a825182ac8d6d9..83fa15d3fb88089fc4e51bcc0632f079e80094ae 100644 --- a/src/service/print/docx.js +++ b/src/service/print/docx.js @@ -329,7 +329,8 @@ async function renderMCQ(question, questionCounter, marks) { qoBody.search("img") >= 0 || qoBody.search("sup") >= 0 || qoBody.search("sub") >= 0 || - qoBody.match(/<p>/g).length > 1 + (qoBody.match(/<p>/g) && qoBody.match(/<p>/g).length > 1) || + (qoBody.match(/<ol>/g) && qoBody.match(/<ol>/g).length >= 1) ? await getStack(qoBody, answerOptions[index]) : [`${answerOptions[index]}. ${cleanHTML(qoBody)}`]; questionOptions.push(qoData); @@ -339,7 +340,8 @@ async function renderMCQ(question, questionCounter, marks) { q.search("img") >= 0 || q.search("sub") >= 0 || q.search("sup") >= 0 || - q.match(/<p>/g).length > 1 + (q.match(/<p>/g) && q.match(/<p>/g).length > 1) || + (q.match(/<ol>/g) && q.match(/<ol>/g).length > 1) ? await getStack(q, questionCounter) : [`${questionCounter}. ${cleanHTML(q)}`]; @@ -432,7 +434,8 @@ async function renderQuestion(question, questionCounter, marks, Type) { question.editorState.question.search("sup") >= 0 || question.editorState.question.search("ol") >= 0 || question.editorState.question.search("ul") >= 0 || - question.editorState.question.match(/<p>/g).length > 1 + (question.editorState.question.match(/<p>/g) && question.editorState.question.match(/<p>/g).length > 1) || + (question.editorState.question.match(/<ol>/g) && question.editorState.question.match(/<ol>/g).length > 1) ) { data = await getStack(question.editorState.question, questionCounter); } else { @@ -457,8 +460,9 @@ async function renderComprehension(question, questionCounter, marks, Type) { question.editorState.question.search("sup") >= 0 || question.editorState.question.search("ol") >= 0 || question.editorState.question.search("ul") >= 0 || - question.editorState.question.match(/<p>/g).length > 1 - ) { + (question.editorState.question.match(/<p>/g) && question.editorState.question.match(/<p>/g).length > 1)|| + (question.editorState.question.match(/<ol>/g) && question.editorState.question.match(/<ol>/g).length > 1) + ) { data = await getStack(question.editorState.question, questionCounter); } else { data = [`${questionCounter}. ${cleanHTML(question.editorState.question)}`]; diff --git a/src/service/print/getdocxdata.js b/src/service/print/getdocxdata.js index 5d29186efd7a5350c34ee7d5e9b8ce712dba84ad..bf166a2cdd6e4317f45eda4c6b853751e2243030 100644 --- a/src/service/print/getdocxdata.js +++ b/src/service/print/getdocxdata.js @@ -476,26 +476,12 @@ function formatOptions(data) { let image; let testimage = data; if (testimage) { - if (testimage.Option1.includes("data:image/")) { - optionArr.push(testimage.Option1); - } else { - optionArr.push(testimage.Option1); - } - if (testimage.Option2.includes("data:image/")) { - optionArr.push(testimage.Option2); - } else { - optionArr.push(testimage.Option2); - } - if (testimage.Option3.includes("data:image/")) { - optionArr.push(testimage.Option3); - } else { - optionArr.push(testimage.Option3); - } - if (testimage.Option4.includes("data:image/")) { - optionArr.push(testimage.Option4); - } else { - optionArr.push(testimage.Option4); - } + console.log("Optiona:", testimage); + optionArr.push(testimage.Option1); + optionArr.push(testimage.Option2); + optionArr.push(testimage.Option3); + optionArr.push(testimage.Option4); + optionArr.push(testimage.height1); optionArr.push(testimage.width1); optionArr.push(testimage.height2); @@ -630,29 +616,91 @@ function headers() { } function displayNumber(data) { - return new TableCell({ - borders: MTFborder, - width: { - size: 300, - type: WidthType.DXA, - }, - margins: { - top: convertInchesToTwip(0.0693701), - bottom: convertInchesToTwip(0.0693701), - left: convertInchesToTwip(0.0693701), - right: convertInchesToTwip(0.0693701), - }, - verticalAlign: VerticalAlign.CENTER, - children: [ - new Paragraph({ - text: data.substr(0, 1), - }), - ], - }); + if (typeof data === "object") { + return new TableCell({ + borders: MTFborder, + width: { + size: 300, + type: WidthType.DXA, + }, + margins: { + top: convertInchesToTwip(0.0693701), + bottom: convertInchesToTwip(0.0693701), + left: convertInchesToTwip(0.0693701), + right: convertInchesToTwip(0.0693701), + }, + verticalAlign: VerticalAlign.CENTER, + children: [ + new Paragraph({ + text: data.text[0], + }), + ], + }); + } else { + return new TableCell({ + borders: MTFborder, + width: { + size: 300, + type: WidthType.DXA, + }, + margins: { + top: convertInchesToTwip(0.0693701), + bottom: convertInchesToTwip(0.0693701), + left: convertInchesToTwip(0.0693701), + right: convertInchesToTwip(0.0693701), + }, + verticalAlign: VerticalAlign.CENTER, + children: [ + new Paragraph({ + text: data.substr(0, 1), + }), + ], + }); + } } +function displayOptionsObject(data, count) { + const arr = []; + if (data.text) { + data.text + .map((text) => { + console.log("Object text:", text); + if (typeof text === "object") { + arr.push(new TextRun(text)); + } else { + arr.push( + new TextRun({ + text: `${text}`, + }) + ); + } + }) + .reduce((prev, curr) => prev.concat(curr), []); + return new TableCell({ + borders: MTFborder, + width: { + size: 4505, + type: WidthType.DXA, + }, + margins: { + top: convertInchesToTwip(0.0693701), + bottom: convertInchesToTwip(0.0693701), + left: convertInchesToTwip(0.0693701), + right: convertInchesToTwip(0.0693701), + }, + verticalAlign: VerticalAlign.CENTER, + children: [ + new Paragraph({ + children: arr, + }), + ], + }); + } +} function displayOptions(option, height, width) { - if (option.includes("data:image/")) { + if (typeof option === "object") { + return displayOptionsObject(option); + } else if (option.includes("data:image/")) { let image = getBufferData(option); return new TableCell({ borders: MTFborder,