Spaces:
Running
Running
Commit
·
61d1de3
1
Parent(s):
94759d3
Update answer on stack of array
Browse files- statics/script.js +14 -3
statics/script.js
CHANGED
@@ -123,11 +123,22 @@ questionEl.addEventListener("keydown", (e) => {
|
|
123 |
|
124 |
/* ─────────────────────── helpers ───────────────────────────── */
|
125 |
function displayQa(data) {
|
126 |
-
|
127 |
-
|
128 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
}
|
130 |
|
|
|
131 |
/* ─────────────────────── bootstrap ─────────────────────────── */
|
132 |
window.addEventListener("DOMContentLoaded", async () => {
|
133 |
try {
|
|
|
123 |
|
124 |
/* ─────────────────────── helpers ───────────────────────────── */
|
125 |
function displayQa(data) {
|
126 |
+
let qHtml = "", aHtml = "";
|
127 |
+
// Parse and bind JSON now as Q&A can be an array with more than 1 component(s)
|
128 |
+
const qaList = Array.isArray(data) ? data : [data];
|
129 |
+
qaList.forEach((item, idx) => {
|
130 |
+
const q = item.question || "[no question]";
|
131 |
+
const a = item.answer || "[no answer]";
|
132 |
+
qHtml += `Q${idx + 1}: ${q}\n`;
|
133 |
+
aHtml += `<strong>Q${idx + 1}:</strong> ${DOMPurify.sanitize(marked.parseInline(q))}<br>`;
|
134 |
+
aHtml += `<strong>A${idx + 1}:</strong> ${DOMPurify.sanitize(marked.parse(a))}<hr>`;
|
135 |
+
});
|
136 |
+
// Type effect with trimming element
|
137 |
+
typeEffect(questionEl, qHtml.trim());
|
138 |
+
setTimeout(() => { answerEl.innerHTML = aHtml.trim(); }, 400);
|
139 |
}
|
140 |
|
141 |
+
|
142 |
/* ─────────────────────── bootstrap ─────────────────────────── */
|
143 |
window.addEventListener("DOMContentLoaded", async () => {
|
144 |
try {
|