2020-01-23 00:10:02 +01:00
|
|
|
$("textarea.markdown").each(function() {
|
|
|
|
async function render(plainText, preview) {
|
|
|
|
const response = await fetch(new Request("/api/markdown/", {
|
|
|
|
method: "POST",
|
|
|
|
credentials: "same-origin",
|
|
|
|
body: plainText,
|
|
|
|
headers: {
|
|
|
|
"Accept": "text/html; charset=UTF-8",
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
|
|
|
|
preview.innerHTML = await response.text();
|
|
|
|
}
|
|
|
|
|
|
|
|
let timeout_id = null;
|
|
|
|
|
2021-02-28 03:36:31 +01:00
|
|
|
this.easy_mde = new EasyMDE({
|
2020-01-23 00:10:02 +01:00
|
|
|
element: this,
|
|
|
|
hideIcons: ["image"],
|
2021-02-05 15:19:29 +01:00
|
|
|
showIcons: ["code", "table"],
|
2020-01-23 00:10:02 +01:00
|
|
|
forceSync: true,
|
|
|
|
previewRender: (plainText, preview) => {
|
|
|
|
if (timeout_id) {
|
|
|
|
clearTimeout(timeout_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
timeout_id = setTimeout(() => {
|
|
|
|
render(plainText, preview);
|
|
|
|
timeout_id = null;
|
|
|
|
}, 500);
|
|
|
|
|
|
|
|
return preview.innerHTML;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})
|