forked from affeldt-aist/coq2html
-
Notifications
You must be signed in to change notification settings - Fork 0
/
coq2html.js
79 lines (71 loc) · 1.79 KB
/
coq2html.js
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
function toggleDisplay(id)
{
var elt = document.getElementById(id);
if (elt.style.display == 'none') {
elt.style.display = 'block';
} else {
elt.style.display = 'none';
}
}
function hideAll(cls)
{
var testClass = new RegExp("(^|s)" + cls + "(s|$)");
var tag = tag || "*";
var elements = document.getElementsByTagName("div");
var current;
var length = elements.length;
for(var i=0; i<length; i++){
current = elements[i];
if(testClass.test(current.className)) {
current.style.display = 'none';
}
}
}
function renderMarkdowns()
{
const md = markdownit({html:true})
.use(texmath, { engine: katex,
delimiters: 'dollars'} );
const elements = document.querySelectorAll('.markdown,.md');
for (let elem of elements) {
elem.innerHTML = md.render(elem.textContent);
}
}
function showDarkmodeWidget()
{
new Darkmode({
time: '0.1s',
label: '🌓',
}).showWidget();
}
function setUpSavingDetails() {
$('details').on('toggle', function(event) {
var id = $(this).attr('id')
var isOpen = $(this).attr('open')
console.log(id, isOpen)
window.localStorage.setItem('details-'+id, isOpen)
})
function setDetailOpenStatus(item) {
if (item.includes('details-')) {
var id = item.split('details-')[1];
var status = window.localStorage.getItem(item)
if (status == 'open'){
$("#"+CSS.escape(id)).attr('open',true)
}
}
}
$( document ).ready(function() {
console.log("document ready: "+localStorage.length);
for (var i = 0; i < localStorage.length; i++) {
console.log("setDetail: "+localStorage.key(i));
setDetailOpenStatus(localStorage.key(i));
}
});
}
function init(cls)
{
hideAll(cls);
renderMarkdowns();
showDarkmodeWidget();
setUpSavingDetails();
}