-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMathCloze.js
More file actions
31 lines (26 loc) · 1.18 KB
/
Copy pathMathCloze.js
File metadata and controls
31 lines (26 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
document.querySelectorAll('.note').forEach(note => {
const uuidEl = note.querySelector('.uuid');
const uuid = uuidEl ? uuidEl.outerHTML : ''; // preserve uuid HTML
if (uuidEl) uuidEl.remove();
let raw = note.innerHTML;
console.log(raw);
raw = raw.replaceAll(/\(\(CLOZE(\d+)\)\)/g,'<span class="cloze$1"><span class="syntax">{</span>');
console.log("\nA:\n");
raw = raw.replaceAll('((HINT))','</span><span class="hint"> <span class="syntax">:</span> ');
console.log("\nB:\n");
raw = raw.replaceAll('((CLEND))','<span class="syntax">}</span></span>');
console.log(raw);
const fields = raw.split("((FIELDSEPARATOR))").map(s => s.trim());
const styled = fields.map((f, i) => {
switch (i) {
case 1: return `<div class="field title">${f}</div>`;
case 2: return `<div class="field prompt">${f}</div>`;
case 3: return `<div class="field background">${f}</div>`;
case 4: return `<div class="field chapter">${f}</div>`;
case 5: return `<div class="field def">${f}</div>`;
case 6: return `<div class="field number">${f}</div>`;
default: return `<div class="field">${f}</div>`;
}
});
note.innerHTML = uuid + styled.join('');
});