Unverified Commit b8333c3c authored by Kartheek Palla's avatar Kartheek Palla Committed by GitHub
Browse files

Merge pull request #229 from snehar-nd/feat/question-paper-docx

#SB-27302 - Accommodate different text formats and fonts in Sunbird Print Preview Service
Showing with 97 additions and 45 deletions
+97 -45
...@@ -329,7 +329,8 @@ async function renderMCQ(question, questionCounter, marks) { ...@@ -329,7 +329,8 @@ async function renderMCQ(question, questionCounter, marks) {
qoBody.search("img") >= 0 || qoBody.search("img") >= 0 ||
qoBody.search("sup") >= 0 || qoBody.search("sup") >= 0 ||
qoBody.search("sub") >= 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]) ? await getStack(qoBody, answerOptions[index])
: [`${answerOptions[index]}. ${cleanHTML(qoBody)}`]; : [`${answerOptions[index]}. ${cleanHTML(qoBody)}`];
questionOptions.push(qoData); questionOptions.push(qoData);
...@@ -339,7 +340,8 @@ async function renderMCQ(question, questionCounter, marks) { ...@@ -339,7 +340,8 @@ async function renderMCQ(question, questionCounter, marks) {
q.search("img") >= 0 || q.search("img") >= 0 ||
q.search("sub") >= 0 || q.search("sub") >= 0 ||
q.search("sup") >= 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) ? await getStack(q, questionCounter)
: [`${questionCounter}. ${cleanHTML(q)}`]; : [`${questionCounter}. ${cleanHTML(q)}`];
...@@ -432,7 +434,8 @@ async function renderQuestion(question, questionCounter, marks, Type) { ...@@ -432,7 +434,8 @@ async function renderQuestion(question, questionCounter, marks, Type) {
question.editorState.question.search("sup") >= 0 || question.editorState.question.search("sup") >= 0 ||
question.editorState.question.search("ol") >= 0 || question.editorState.question.search("ol") >= 0 ||
question.editorState.question.search("ul") >= 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); data = await getStack(question.editorState.question, questionCounter);
} else { } else {
...@@ -457,8 +460,9 @@ async function renderComprehension(question, questionCounter, marks, Type) { ...@@ -457,8 +460,9 @@ async function renderComprehension(question, questionCounter, marks, Type) {
question.editorState.question.search("sup") >= 0 || question.editorState.question.search("sup") >= 0 ||
question.editorState.question.search("ol") >= 0 || question.editorState.question.search("ol") >= 0 ||
question.editorState.question.search("ul") >= 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); data = await getStack(question.editorState.question, questionCounter);
} else { } else {
data = [`${questionCounter}. ${cleanHTML(question.editorState.question)}`]; data = [`${questionCounter}. ${cleanHTML(question.editorState.question)}`];
......
...@@ -476,26 +476,12 @@ function formatOptions(data) { ...@@ -476,26 +476,12 @@ function formatOptions(data) {
let image; let image;
let testimage = data; let testimage = data;
if (testimage) { if (testimage) {
if (testimage.Option1.includes("data:image/")) { console.log("Optiona:", testimage);
optionArr.push(testimage.Option1); optionArr.push(testimage.Option1);
} else { optionArr.push(testimage.Option2);
optionArr.push(testimage.Option1); optionArr.push(testimage.Option3);
} optionArr.push(testimage.Option4);
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);
}
optionArr.push(testimage.height1); optionArr.push(testimage.height1);
optionArr.push(testimage.width1); optionArr.push(testimage.width1);
optionArr.push(testimage.height2); optionArr.push(testimage.height2);
...@@ -630,29 +616,91 @@ function headers() { ...@@ -630,29 +616,91 @@ function headers() {
} }
function displayNumber(data) { function displayNumber(data) {
return new TableCell({ if (typeof data === "object") {
borders: MTFborder, return new TableCell({
width: { borders: MTFborder,
size: 300, width: {
type: WidthType.DXA, size: 300,
}, type: WidthType.DXA,
margins: { },
top: convertInchesToTwip(0.0693701), margins: {
bottom: convertInchesToTwip(0.0693701), top: convertInchesToTwip(0.0693701),
left: convertInchesToTwip(0.0693701), bottom: convertInchesToTwip(0.0693701),
right: convertInchesToTwip(0.0693701), left: convertInchesToTwip(0.0693701),
}, right: convertInchesToTwip(0.0693701),
verticalAlign: VerticalAlign.CENTER, },
children: [ verticalAlign: VerticalAlign.CENTER,
new Paragraph({ children: [
text: data.substr(0, 1), 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) { 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); let image = getBufferData(option);
return new TableCell({ return new TableCell({
borders: MTFborder, borders: MTFborder,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment