Spaces:
Sleeping
Sleeping
File size: 5,751 Bytes
12f3253 66e25d1 ec03973 66e25d1 12f3253 66e25d1 53339de 66e25d1 12f3253 66e25d1 12f3253 66e25d1 ec03973 66e25d1 12f3253 66e25d1 12f3253 66e25d1 12f3253 ec03973 12f3253 53339de 12f3253 66e25d1 12f3253 53339de 12f3253 53339de 66e25d1 | 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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
async function write_markdown() {
let names = ["introduction", "transform", "likelihood", "posterior", "forward_process",
"backward_process", "fit_posterior", "posterior_transform", "deconvolution",
"cond_kl", "approx_gauss", "non_expanding", "stationary", "reference", "about"];
// names = names.slice(-1)
let data = await fetch("file/data.json").then(response => response.json());
names.forEach((name, index) => {
let elem_zh = document.getElementById("md_" + name + "_zh");
if (elem_zh != null) { data[name+"_zh"] = elem_zh.outerHTML; console.log(name);}
const elem_en = document.getElementById("md_" + name + "_en");
if (elem_en != null) { data[name+"_en"] = elem_en.outerHTML; }
});
let a = document.createElement('a');
a.href = "data:application/octet-stream," + encodeURIComponent(JSON.stringify(data));
a.download = "data.json";
a.click();
}
async function insert_markdown() {
let names = ["introduction", "transform", "likelihood", "posterior", "forward_process",
"backward_process", "fit_posterior", "posterior_transform", "deconvolution",
"cond_kl", "approx_gauss", "non_expanding", "stationary", "reference", "about"];
let data = await fetch("file/data.json").then(response => response.json());
for (let i = 0; i < names.length; i++) {
name = names[i];
const markdown_zh = document.createElement('div');
markdown_zh.id = "md_" + name + "_zh";
markdown_zh.style.display = "none";
markdown_zh.innerHTML = data[name+"_zh"]
// fetch('file/Markdown/zh/' + name + ".html").then(response => response.text()).then(text => markdown_zh.innerHTML = text)
const markdown_en = document.createElement('div');
markdown_en.id = "md_" + name + "_en";
markdown_en.style.display = "block";
markdown_en.innerHTML = data[name+"_en"]
// fetch('file/Markdown/en/' + name + ".html").then(response => response.text()).then(text => markdown_en.innerHTML = text)
const accord = document.getElementById(name).children[2];
accord.appendChild(markdown_zh);
accord.appendChild(markdown_en);
}
}
function control_language() {
const names = ["introduction", "transform", "likelihood", "posterior", "forward_process",
"backward_process", "fit_posterior", "posterior_transform", "deconvolution",
"cond_kl", "approx_gauss", "non_expanding", "stationary", "reference", "about"];
var is_zh = document.getElementById("switch_language").checked;
for (let i = 0; i < names.length; i++) {
name = names[i];
zh_display = is_zh ? "block" : "none";
en_display = is_zh ? "none" : "block";
md_zh = document.getElementById("md_" + name + "_zh");
md_en = document.getElementById("md_" + name + "_en");
md_zh.style.display = zh_display;
md_en.style.display = en_display;
}
}
function control_accordion() {
open = document.getElementById("switch_accordion").checked;
all_accords = document.getElementsByClassName("label-wrap");
for (let i = 0; i < all_accords.length; i++) {
const accord = all_accords[i];
const is_open = accord.classList.contains("open");
if (is_open != open) {
accord.click();
}
}
}
function create_switch(id, left_text, right_text, callback) {
var input = document.createElement("input");
input.type = "checkbox";
input.id = id;
input.checked = false;
input.addEventListener("change", callback);
var slider = document.createElement("span");
slider.className = "switchslider";
var switchbar = document.createElement("label");
switchbar.className = "switchbar";
switchbar.appendChild(input);
switchbar.appendChild(slider);
var div = document.createElement("div");
div.style.lineHeight = "30px";
div.style.fontSize = "18px";
var left_label = document.createElement("span");
left_label.innerText = left_text;
var right_label = document.createElement("span");
right_label.innerText = right_text;
div.appendChild(left_label);
div.appendChild(switchbar);
div.appendChild(right_label);
return div;
}
function add_switch() {
switch_accordion = create_switch("switch_accordion", "Collapse", "Expand", control_accordion);
switch_language = create_switch("switch_language", "English", "Chinese", control_language);
switch_accordion.style.float = "right";
switch_language.style.float = "left";
var state = document.createElement("span");
state.appendChild(switch_language);
state.appendChild(switch_accordion);
state.style.marginBottom = "20px"
const elem = document.getElementById("introduction");
elem.insertAdjacentElement("beforebegin", state);
switch_accordion.children[1].click();
switch_accordion.children[1].click();
}
function katex_render(name) {
const elem = document.getElementById(name);
if (elem == null) { return; }
var text = elem.innerText.replaceAll("{underline}", "_");
text = "\\begin{align}\n" + text + "\n\\end{align}";
katex.render(text, elem, {displayMode: true});
}
function insert_special_formula() {
katex_render("zh_fit_0");
katex_render("zh_fit_1");
katex_render("zh_fit_2");
katex_render("zh_cond_kl_1");
katex_render("zh_cond_kl_2");
katex_render("zh_cond_kl_3");
katex_render("en_fit_0");
katex_render("en_fit_1");
katex_render("en_fit_2");
katex_render("en_cond_kl_1");
katex_render("en_cond_kl_2");
katex_render("en_cond_kl_3");
}
|