diff options
| author | rubenwardy <rw@rubenwardy.com> | 2020-01-22 23:10:02 +0000 |
|---|---|---|
| committer | rubenwardy <rw@rubenwardy.com> | 2020-01-22 23:10:06 +0000 |
| commit | 595d6ea3b6d663080448085cc2b0c9473388bc37 (patch) | |
| tree | 09c7841f9ff18a6bb5a85af6a8b83d7c1e2f3d97 /app/public/static | |
| parent | 71fa62fd6a10b3c39e236b65e5f4054e71770e2b (diff) | |
| download | cheatdb-595d6ea3b6d663080448085cc2b0c9473388bc37.tar.xz | |
Use server-side markdown renderer in WYSIWYG preview
Fixes #117
Diffstat (limited to 'app/public/static')
| -rw-r--r-- | app/public/static/markdowntextarea.js | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/app/public/static/markdowntextarea.js b/app/public/static/markdowntextarea.js new file mode 100644 index 0000000..c2ba345 --- /dev/null +++ b/app/public/static/markdowntextarea.js @@ -0,0 +1,34 @@ +$("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; + + new EasyMDE({ + element: this, + hideIcons: ["image"], + forceSync: true, + previewRender: (plainText, preview) => { + if (timeout_id) { + clearTimeout(timeout_id); + } + + timeout_id = setTimeout(() => { + render(plainText, preview); + timeout_id = null; + }, 500); + + return preview.innerHTML; + } + }); +}) |
