function QuestionPaperPreview(jsonData){ // The provided JSON data // console.log(jsonData) // start Remove
tag var jsonDat = jsonData; // Remove
tags only with
tags
function removeEmptyPTags(htmlString) {
var tempdiv = document.createElement('div');
tempdiv.innerHTML = htmlString;
var paragraphs = tempdiv.querySelectorAll('p');
paragraphs.forEach(function(paragraph) {
if (paragraph.innerHTML.trim() === '
') {
paragraph.remove();
}
});
return tempdiv.innerHTML;
}
// Recursive function to modify HTML content in an object
function modifyHTMLProperties(obj) {
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
if (typeof obj[key] === 'string') {
// If the property is a string, modify it
obj[key] = removeEmptyPTags(obj[key]);
} else if (typeof obj[key] === 'object') {
// If the property is an object, recursively modify its properties
modifyHTMLProperties(obj[key]);
}
}
}
}
modifyHTMLProperties(jsonDat);
//end Remove
tag function convertToLatex(text, mathstatus) { // console.log('convertToLatex : ', mathstatus); // console.log('convertToLatex text : ', text); // const mathStatusBoolean = JSON.parse(mathstatus); // Check if the text contains
tags if (!/
|<\/p>/i.test(text)) {
if (mathstatus === 'Math') {
// Use MathJax to convert the text to LaTeX
const cov = MathJax.tex2chtml(text).outerHTML;
// console.log('Latex Full : ', cov);
const onlyMath = convertMathJaxToLatex(cov)
// console.log('Latex small : ', onlyMath);
return onlyMath;
} else {
return text;
}
} else {
return text;
}
}
function convertMathJaxToLatex(mathJaxCode) {
// Replace MathJax-specific tags and attributes
let latexCode = mathJaxCode
.replace(/ ', ' ');//add the id for Section Title
// console.log(section.section_attempt_any);
if (section.attributes.AttemptAny) {
var sectionAttempt = ` Attempt Any : ${section.attributes.AttemptAny} Marks: ${section.section_marks} ', ' ');
// const questions = section.questions;
// Add appropriate indentation for nested sections
const indentation = " ".repeat(depth);
// if (section.section_attempt_any === '') {
// sectionAttempt = sectionAttempt.replace(' ', ' ')
// }
// if (section.section_marks === '') {
// sectionMark = sectionMark.replace(' ', ' ')
// }
questionPaper += `${indentation} ','').replace(' ${cleanedText}) ', ` `)
if (question.attributes.AttemptAny) {
var questionGroupAttempt = ` Attempt Any : ${question.attributes.AttemptAny} Marks : ${question.group_marks} ', ' ')
// if (question.group_attempt_any === '') {
// questionGroupAttempt = questionGroupAttempt.replace(' ', ' ')
// }
// if (question.group_marks === '') {
// questionGroupMark = questionGroupMark.replace(' ', ' ')
// }
questionPaper += ` ','').replace(' ${cleanedText}) ', ' ');
const questionTex = question.question;
const questionText = questionTex.replaceAll(' ', ` `);
// console.log(questionText);
const questionDescriptio = question.question_description;
const questionDescription = questionDescriptio.replaceAll(' ', ' ')
const mathstatus = question.descriptionMath;
const titlemathstatus = question.titleMath;
console.log('questionText : ', questionText)
console.log('titlemathstatus : ', titlemathstatus)
if (question.marks == 0 || question.marks == '' ) {
var questionMark = ` Marks :${question.marks} ', ' ')
}
// questionPaper += ` ',' ')
var choiceClass = ''
if (math === 'Math') {
choiceClass = 'text-option-align2';
}else{
choiceClass = 'text-option-align';
}
const answerA = answers[i] ? `${optionA}. ${convertToLatex(answers[i].choice_name, math)}` : '';
console.log('choice latex : ',answerA);
// const answerB = answers[i + 1] ? `${optionB}. ${convertToLatex(answers[i + 1].choice_name, mathstatus)}` : '';
if (multipleAnswer == 'false') {
questionPaper += ` ${answerA.padEnd(10)} ${answerA.padEnd(10)} tags
// console.log(text);
// // console.log("ff")
// if (!/ |<\/p>/i.test(text)) {
// // console.log('text:' , text)
// if (mathStatusBoolean) {
// // console.log('text1:' , text)
// // Use MathJax to convert the text to LaTeX
// const cov = MathJax.tex2chtml(text).outerHTML;
// console.log('cov:' , cov)
// return cov;
// } else {
// // Return the text as-is
// return text;
// }
// } else {
// console.log("pq")
// const cov = MathJax.tex2chtml(text).outerHTML;
// console.log('cov:' , cov)
// return cov;
// // Return the text as-is
// return text;
// }style="margin-left:27px;position: absolute;right: 546px;bottom: 10px;"
// }${title}
${questionPaperDescription}
"; // Add a newline for separation
// Process each section
sections.forEach((section, sectionIndex) => {
depth2=0
description_align =28;
// console.log(sectionIndex);
const sectionTitle = section.section_title;
const modifiedSectionTitle = sectionTitle.replaceAll('
${modifiedSectionTitle}${sectionMark}${sectionAttempt}${indentation}${sectionDescription}`;
displayQuestions(section)
});
// Return the formatted question paper
// console.log(questionPaper);
return questionPaper;
}
var depth2 =0
var description_align =25;
function displayQuestions(data,parentSno =''){
var questionIndentation = " ".repeat(depth2);
console.log(data)
var dataa =data.questions;
dataa.forEach((question, index) =>{
console.log(question.descriptionMath);
var currentSno = parentSno + (index + 1) + '.';
console.log('currentSno : ', currentSno);
var temp_sno= currentSno.slice(0,-1)
var currentSno_length =currentSno.length-(currentSno.length/2)
console.log('currentSno_length : ', currentSno_length);
if (currentSno_length == 1) {
description_align =27
} else if (currentSno_length == 2) {
description_align =20
}else if(currentSno_length == 3){
description_align =48
}else if(currentSno_length == 4) {
description_align =62
}
else if(currentSno_length == 5) {
description_align =78
}
if(question.descriptionMath == 'Math'){
description_align = -364
}
var GroupQuestionTilteAlign = 0;
if (question.group_title) {
let cleanedTex = question.attributes.No.replace(/\s+/g, ' ').trim();
let cleanedText=cleanedTex.replace('