Spaces:
Running
Running
Update index.html
Browse files- index.html +60 -9
index.html
CHANGED
|
@@ -206,23 +206,74 @@
|
|
| 206 |
<p class=MsoNormal>[SECTION MARKS] ${section.sectionMarks}</p>
|
| 207 |
<p class=MsoNormal> </p>`;
|
| 208 |
section.questionBlocks.forEach((block, qIndex) => {
|
| 209 |
-
const questionTextMatch = block.match(/\*\*\d+\.\s*(.*?)\*\*/);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 210 |
const questionText = questionTextMatch ? questionTextMatch[1].trim() : '';
|
| 211 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 212 |
const options = [];
|
| 213 |
-
const optionMatches =
|
| 214 |
for (const match of optionMatches) {
|
| 215 |
options.push({ letter: match[1], text: match[2].trim() });
|
| 216 |
}
|
| 217 |
options.splice(4);
|
| 218 |
-
|
|
|
|
| 219 |
const correctLetter = correctAnswerMatch ? correctAnswerMatch[1].trim() : '';
|
| 220 |
-
|
|
|
|
| 221 |
const explanation = explanationMatch ? explanationMatch[1].trim() : '';
|
| 222 |
-
|
| 223 |
-
const
|
| 224 |
-
|
| 225 |
-
|
|
|
|
|
|
|
|
|
|
| 226 |
${options.map((opt, i) => `
|
| 227 |
<p class=MsoNormal>${opt.letter === correctLetter ? '*' : ''}[${i + 1}] ${opt.text}</p>
|
| 228 |
`).join('')}
|
|
|
|
| 206 |
<p class=MsoNormal>[SECTION MARKS] ${section.sectionMarks}</p>
|
| 207 |
<p class=MsoNormal> </p>`;
|
| 208 |
section.questionBlocks.forEach((block, qIndex) => {
|
| 209 |
+
// const questionTextMatch = block.match(/\*\*\d+\.\s*(.*?)\*\*/);
|
| 210 |
+
let processedBlock = block;
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
const questionTextMatch = processedBlock.match(/\*\*\d+\.\s*(.*?)\*\*/);
|
| 214 |
const questionText = questionTextMatch ? questionTextMatch[1].trim() : '';
|
| 215 |
+
let chartsection = '';
|
| 216 |
+
const chartTypeRegex = /(pie\s*chart|bar\s*chart|line\s*chart|doughnut|radar|polar\s*area)/gi;
|
| 217 |
+
const chartMatch = processedBlock.match(chartTypeRegex);
|
| 218 |
+
let chartType = 'bar';
|
| 219 |
+
const chartTypeMap = { 'pie chart': 'pie', 'bar chart': 'bar', 'line chart': 'line', 'doughnut': 'doughnut', 'radar': 'radar', 'polar area': 'polarArea' };
|
| 220 |
+
|
| 221 |
+
if (chartMatch) chartType = chartTypeMap[chartMatch[0].toLowerCase()] || 'bar';
|
| 222 |
+
|
| 223 |
+
const tableMatches = processedBlock.match(/(\|.*\|(\n\|.*\|)+)/g);
|
| 224 |
+
if (tableMatches) {
|
| 225 |
+
for (const table of tableMatches) {
|
| 226 |
+
const htmlTable = convertMarkdownTableToHTML(table);
|
| 227 |
+
const tempDiv = document.createElement('div');
|
| 228 |
+
tempDiv.innerHTML = htmlTable;
|
| 229 |
+
const tableEl = tempDiv.querySelector('table');
|
| 230 |
+
const headers = Array.from(tableEl.rows[0].cells).map(cell => cell.textContent.replace(/(<([^>]+)>)/gi, '').trim());
|
| 231 |
+
const rows = Array.from(tableEl.rows).slice(1).map(row => Array.from(row.cells).map(cell => parseFloat(cell.textContent) || cell.textContent.trim()));
|
| 232 |
+
|
| 233 |
+
const canvas = document.createElement('canvas');
|
| 234 |
+
canvas.width = 600;
|
| 235 |
+
canvas.height = 400;
|
| 236 |
+
canvas.style.position = 'fixed';
|
| 237 |
+
canvas.style.left = '-9999px';
|
| 238 |
+
document.body.appendChild(canvas);
|
| 239 |
+
|
| 240 |
+
new Chart(canvas.getContext('2d'), {
|
| 241 |
+
type: chartType,
|
| 242 |
+
data: { labels: rows.map(r => r[0]), datasets: [{
|
| 243 |
+
label: headers[1],
|
| 244 |
+
data: rows.map(r => r[1]),
|
| 245 |
+
backgroundColor: ['rgba(255, 99, 132, 0.2)','rgba(54, 162, 235, 0.2)','rgba(255, 206, 86, 0.2)','rgba(75, 192, 192, 0.2)','rgba(153, 102, 255, 0.2)'],
|
| 246 |
+
borderColor: ['rgba(255, 99, 132, 1)','rgba(54, 162, 235, 1)','rgba(255, 206, 86, 1)','rgba(75, 192, 192, 1)','rgba(153, 102, 255, 1)'],
|
| 247 |
+
borderWidth: 1
|
| 248 |
+
}]},
|
| 249 |
+
options: { animation: false, responsive: false, scales: chartType === 'pie' ? null : { y: { beginAtZero: true } } }
|
| 250 |
+
});
|
| 251 |
+
|
| 252 |
+
const base64 = canvas.toDataURL('image/png');
|
| 253 |
+
document.body.removeChild(canvas);
|
| 254 |
+
processedBlock = processedBlock.replace(table, `${htmlTable}<br><div style="text-align:center; margin:20px 0"><img src="${base64}" style="max-width:600px; display:inline-block"></div>`);
|
| 255 |
+
const chartsection = processedBlock.replace(/\*\*\d+\.\s*(.*?)\*\*/, ``);
|
| 256 |
+
}
|
| 257 |
+
}
|
| 258 |
const options = [];
|
| 259 |
+
const optionMatches = processedBlock.matchAll(/([a-d])\)\s*(.*?)\n/g);
|
| 260 |
for (const match of optionMatches) {
|
| 261 |
options.push({ letter: match[1], text: match[2].trim() });
|
| 262 |
}
|
| 263 |
options.splice(4);
|
| 264 |
+
|
| 265 |
+
const correctAnswerMatch = processedBlock.match(/\*\*Correct Answer:\*\*\s*([a-d])\)/i);
|
| 266 |
const correctLetter = correctAnswerMatch ? correctAnswerMatch[1].trim() : '';
|
| 267 |
+
|
| 268 |
+
const explanationMatch = processedBlock.match(/\*\*Explanation:\*\*\s*(.*)/);
|
| 269 |
const explanation = explanationMatch ? explanationMatch[1].trim() : '';
|
| 270 |
+
|
| 271 |
+
const tagMatch = processedBlock.match(/\[TAG:\s*(.*?)\]/);
|
| 272 |
+
const difficultyMatch = processedBlock.match(/\[DIFFICULTY:\s*(.*?)\]/);
|
| 273 |
+
|
| 274 |
+
htmlContent += `
|
| 275 |
+
|
| 276 |
+
<p class=MsoNormal><b>Q.${qIndex + 1})</b> ${questionText}</p><br>${chartsection}
|
| 277 |
${options.map((opt, i) => `
|
| 278 |
<p class=MsoNormal>${opt.letter === correctLetter ? '*' : ''}[${i + 1}] ${opt.text}</p>
|
| 279 |
`).join('')}
|