-
Notifications
You must be signed in to change notification settings - Fork 0
/
Front_Template.html
45 lines (33 loc) · 1.05 KB
/
Front_Template.html
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<h4>{{Title}}</h4>
<div id='text'>{{Text}}</div>
<script>
clozeSequenceEnvironment = {
/*
* Configuration
*/
delimiter: {
START: "li",
END: "li",
type: "tag" // Use "tag" if the cloze is inside an HTML element, else "token"
},
text: document.querySelector('#text'),
// Escape RegEx special tokens
escapeRegEx(str) {
return str.replace(/([\\^$.|?*+()\[\]{}])/g, "\\$1")
}
}
csEnv = clozeSequenceEnvironment;
if (csEnv.delimiter.type == "tag") {
document.querySelectorAll(csEnv.delimiter.START).forEach(
cloze => {
cloze.classList.add("cloze", "hidden-cloze");
}
)
} else {
csEnv.delimiter.START = escapeRegEx(csEnv.delimiter.START);
csEnv.delimiter.END = escapeRegEx(csEnv.delimiter.END);
// Remove the delimiters and put the content inside a span.
let re = new RegExp(`${csEnv.delimiter.START}(.+?)${csEnv.delimiter.END}`, "g");
text.innerHTML = text.innerHTML.replace(re, '<span class="cloze hidden-cloze">$1</span>');
}
</script>