aboutsummaryrefslogtreecommitdiff
path: root/src/main/resources/js/fileview.js
diff options
context:
space:
mode:
authorMarvin Borner2019-04-07 15:49:26 +0200
committerMarvin Borner2019-04-07 15:49:26 +0200
commit4e2024432ee680f98d91d07b050ac60151ebec4c (patch)
tree8f388c3349d9081625846d00770e5b44ef38bf3c /src/main/resources/js/fileview.js
parent92807cfb7249eff1d96b70aa33a46c9eb6c0e733 (diff)
Added prettifying and previews of html/markdown
Diffstat (limited to 'src/main/resources/js/fileview.js')
-rw-r--r--src/main/resources/js/fileview.js22
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";
+ }
+ });
+}