diff options
Diffstat (limited to 'src/main/resources/js/fileview.js')
-rw-r--r-- | src/main/resources/js/fileview.js | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/main/resources/js/fileview.js b/src/main/resources/js/fileview.js new file mode 100644 index 0000000..a9cb5be --- /dev/null +++ b/src/main/resources/js/fileview.js @@ -0,0 +1,22 @@ +if (extension === "md" || extension === "html") { + if (extension === "md") + document.getElementById("preview").innerHTML = marked(document.getElementById("content").innerText); + else if (extension === "html") + document.getElementById("preview").innerHTML = marked(document.getElementById("content").innerText); + + document.getElementById("preview").style.display = "block"; + document.getElementById("switch").style.display = "block"; + document.getElementById("content").style.display = "none"; + + document.getElementById("switch").addEventListener("click", () => { + if (document.getElementById("preview").style.display === "block") { + document.getElementById("switch").innerText = "Show preview"; + document.getElementById("preview").style.display = "none"; + document.getElementById("content").style.display = "block"; + } else { + document.getElementById("switch").innerText = "Show raw"; + document.getElementById("preview").style.display = "block"; + document.getElementById("content").style.display = "none"; + } + }); +} |