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(text); // Parse mathstatus into a boolean const mathStatusBoolean = JSON.parse(mathstatus); // Check if the text contains
tags if (!/
|<\/p>/i.test(text)) { if (mathStatusBoolean) { // Use MathJax to convert the text to LaTeX const cov = MathJax.tex2chtml(text).outerHTML; return cov; } else { // Return the text as-is return text; } } else { // Return the text as-is return text; } } // Initialize the formatted question paper string let questionPaper = ""; // Function to recursively convert JSON to a formatted question paper function convertJSONToQuestionPaper(data, depth = 0, sectionIndex , questionIndex = 1) { const sections = data.sections; const questionPaperTitle = data.question_paper_title; const questionPaperDescription = data.question_paper_description; var title = removeHtmlTags(questionPaperTitle) // Wrap the heading elements in
', '
');//add the id for Section Title // console.log(section.section_attempt_any); if (section.section_attempt_any) { var sectionAttempt = `
Attempt Any : ${section.section_attempt_any}
`; } else { var sectionAttempt = ``; } if (section.section_marks == 0 || section.section_marks == '') { var sectionMark = `
`; } else { var sectionMark = `
Marks: ${section.section_marks}
`; } var displayMarks = section.section_display_marks; if (displayMarks === 'false') { var parser = new DOMParser(); var doc = parser.parseFromString(sectionMark, 'text/html'); var questionMarkElement = doc.body.firstChild; questionMarkElement.setAttribute('hidden', 'hidden'); sectionMark =questionMarkElement.outerHTML var doc = parser.parseFromString(sectionAttempt, 'text/html'); var questionMarkElement = doc.body.firstChild; questionMarkElement.style.marginRight = '106px'; console.log(questionMarkElement); sectionAttempt =questionMarkElement.outerHTML } const sectionDescriptio = section.section_description; const sectionDescription = sectionDescriptio.replaceAll('', '
'); // 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('
','') var question_id_length =cleanedText.length; if (question_id_length == 1) { GroupQuestionTilteAlign =15 } else if (question_id_length == 3) { GroupQuestionTilteAlign =33 }else if(question_id_length == 5){ GroupQuestionTilteAlign =47 }else if(question_id_length == 7) { GroupQuestionTilteAlign =63 }else if(question_id_length == 4) { GroupQuestionTilteAlign =40 }else if(question_id_length == 6) { GroupQuestionTilteAlign =54 }else if(question_id_length == 2){ GroupQuestionTilteAlign =23 } // const questionId =`${cleanedText})
` const questionId =cleanedText const questionGroupSetP = `${question.group_title}`; const questionGroupmodify =questionGroupSetP.replaceAll('', `
`) if (question.group_attempt_any) { var questionGroupAttempt = `
Attempt Any : ${question.group_attempt_any}
` }else{ var questionGroupAttempt = `` } if (question.group_marks === 0 || question.group_marks === '') { var questionGroupMark = `
` }else{ var questionGroupMark = `
Marks : ${question.group_marks}
` } var displayMarks = question.group_display_marks; if (displayMarks === 'false') { var parser = new DOMParser(); var doc = parser.parseFromString(questionGroupMark, 'text/html'); var questionMarkElement = doc.body.firstChild; questionMarkElement.setAttribute('hidden', 'hidden'); questionGroupMark =questionMarkElement.outerHTML } const questionGroupDescriptio = question.group_description; const questionGroupDescription = questionGroupDescriptio.replaceAll('', '
') // if (question.group_attempt_any === '') { // questionGroupAttempt = questionGroupAttempt.replace('
', '
') // } // if (question.group_marks === '') { // questionGroupMark = questionGroupMark.replace('
', '
') // } questionPaper += `
','').replace('
','') var question_id_length =cleanedText.length; if (question_id_length == 1) { GroupQuestionTilteAlign =14 } else if (question_id_length == 3) { GroupQuestionTilteAlign =26 }else if(question_id_length == 5){ GroupQuestionTilteAlign =41 }else if(question_id_length == 7) { GroupQuestionTilteAlign =54 }else if(question_id_length == 2) { GroupQuestionTilteAlign =25 }else if(question_id_length == 4) { GroupQuestionTilteAlign =42 }else if(question_id_length == 6) { GroupQuestionTilteAlign =58 } // console.log(question); // const questionId =`${cleanedText})
`; const questionI =cleanedText; var questionId = questionI.replace('', '
'); const questionTex = question.question; const questionText = questionTex.replaceAll('
', `
`); // console.log(questionText); const questionDescriptio = question.question_description; const questionDescription = questionDescriptio.replaceAll('
', '
') const mathstatus = question.is_math_enabled; if (question.marks == 0 || question.marks == '' ) { var questionMark = `
`; } else { var questionMark = `
Marks :${question.marks}
`; } var displayMarks =question.display_marks if (displayMarks === 'false') { var parser = new DOMParser(); var doc = parser.parseFromString(questionMark, 'text/html'); var questionMarkElement = doc.body.firstChild; questionMarkElement.setAttribute('hidden', 'hidden'); questionMark =questionMarkElement.outerHTML } // console.log(questionMark); const multipleAnswer =question.question_sub_type; if (question.marks == '') { questionMark = questionMark.replace('', '
') } // questionPaper += `
','
') const answerA = answers[i] ? `${optionA}. ${convertToLatex(answers[i].choice_name, math)}` : ''; // 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; } }