diff --git a/QuestionPaperPreview.js b/QuestionPaperPreview.js index 7c6952a..31cfc9e 100644 --- a/QuestionPaperPreview.js +++ b/QuestionPaperPreview.js @@ -1,200 +1,192 @@ - function QuestionPaperPreview(jsonData){ -// The provided JSON data -// console.log(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]);
+ 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);
-
+ modifyHTMLProperties(jsonDat);
+
//end Remove
tag - - - -function convertToLatex(text, mathstatus) { - // 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; + + + function convertToLatex(text, mathstatus) { + // 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; } - } else { - // Return the text as-is - return text; - } -} -// Initialize the formatted question paper string -let questionPaper = ""; - - -function CheakQnType(question, questionIndex, depth,nested) { - const questionType = question.question_type; - if (questionType) { - processQuestion(question, questionIndex, depth,nested); - }else { - GroupQuestion(question, questionIndex, depth); } + // Initialize the formatted question paper string + let questionPaper = ""; + -} -var count =0 -var count1 =0 -var romanNumerals = ["", "i", "ii", "iii", "iv", "v", "vi", "vii", "viii", "ix", "x"]; -function processQuestion(question, questionIndex, depth,nested) { - // console.log('question Data') - // console.log(question); - - const questionTex = question.question; - const questionText = questionTex.replace('
', '
'); - const questionDescription = question.question_description; - const mathstatus = question.is_math_enabled; - const questionMark = question.marks; - const multipleAnswer =question.question_sub_type; // this gives true or false to chaeck multiple answers or not - // Add appropriate indentation for nested questions - const questionIndentation = " ".repeat(depth + 1); - console.log(questionIndentation) - if (nested == 1) {// this adds the inside the questionGroup - count1++; - var romanNumeral=romanNumerals[count1]; - questionPaper += `
Marks :${questionMark}
Marks :${questionMark}
', '
') - count++ - questionPaper += `
Marks : ${question.group_marks}
Attempt Any : ${question.group_attempt_any}
', '
');//add the id for Section Title + var sectionAttempt = `
Attempt Any : ${section.section_attempt_any}
`; + var sectionMark = `Marks: ${section.section_marks}
`; + const sectionDescription = section.section_description; + // const questions = section.questions; + // Add appropriate indentation for nested sections + const indentation = " ".repeat(depth); + if (section.section_attempt_any === '') { + sectionAttempt = sectionAttempt.replace('', '
') + } - // Process each section - sections.forEach((section, sectionIndex) => { - const sectionTitle = section.section_title; - const modifiedSectionTitle = sectionTitle.replace('
', '
');//add the id for Section Title - - const sectionAttempt = `
Attempt Any : ${section.section_attempt_any}
`; - const sectionMark = `Marks: ${section.section_marks}
`; - const sectionDescription = section.section_description; - const questions = section.questions; + if (section.section_marks === '') { + sectionMark = sectionMark.replace('', '
') + } + questionPaper += `${indentation}
', '
') + var questionGroupAttempt = `
Attempt Any : ${question.group_attempt_any}
` + var questionGroupMark = `Marks : ${question.group_marks}
` + if (question.group_attempt_any === '') { + questionGroupAttempt = questionGroupAttempt.replace('', '
') + } + + if (question.group_marks === '') { + questionGroupMark = questionGroupMark.replace('
', '
') + } + + questionPaper += `
', '
'); + console.log(questionText); + const questionDescription = question.question_description; + const mathstatus = question.is_math_enabled; + var questionMark = `
Marks :${question.marks}
`; + // console.log(questionMark); + const multipleAnswer =question.question_sub_type; + if (question.marks == '') { + questionMark = questionMark.replace('', '
') + } + + questionPaper += `