-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
48 lines (39 loc) · 1.44 KB
/
app.js
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
const defaultText = `Hello ✋
=======
This is a live markdown editor built in plain HTML,<br> CSS and AlpineJS 🗻
Write your code on the left area and watch the result on real time here!
### Some useful links:
* <a href="https://github.com/ms0uto" target="_blank">Markdown guide</a>
* <a href="https://github.com/ms0uto" target="_blank">Personal github page</a>
### It can even do images!
![Code](https://blog.codepen.io/wp-content/uploads/2012/06/Button-Fill-Black-Small.png)
`
function download() {
var text = document.getElementById("text-area").value;
var blob = new Blob([text], { type: "text/markdown" });
var anchor = document.createElement("a");
date = Date.now();
anchor.download = `markdown-${date}.md`;
anchor.href = window.URL.createObjectURL(blob);
anchor.target = "_blank";
anchor.style.display = "none"; // just to be safe!
document.body.appendChild(anchor);
anchor.click();
document.body.removeChild(anchor);
}
function open() {
inputfile.click();
document.getElementById("inputfile").addEventListener("change", function () {
var fr = new FileReader();
fr.onload = function () {
var textarea = document.getElementById("text-area");
textarea.value = fr.result;
document.getElementById("markdown").innerHTML = marked.parse(fr.result);
textarea.focus();
};
fr.readAsText(this.files[0]);
});
}
function toggleTheme() {
document.body.classList.toggle("theme-light");
}