-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
119 lines (97 loc) · 3.61 KB
/
main.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
document.addEventListener("DOMContentLoaded", function() {
var editor = CodeMirror.fromTextArea(document.getElementById("editor"), {
mode: "markdown",
lineNumbers: true,
theme: "default"
});
function updatePreview() {
var preview = document.getElementById("preview");
var markdownText = editor.getValue();
preview.innerHTML = marked.parse(markdownText);
updateStatus();
}
editor.on("change", updatePreview);
window.insertText = function(startTag, endTag) {
var doc = editor.getDoc();
var cursor = doc.getCursor();
var selectedText = doc.getSelection();
doc.replaceSelection(startTag + selectedText + endTag);
};
window.insertHeading = function() {
insertText("#", "");
};
window.insertQuote = function() {
insertText("> ", "");
};
window.insertList = function(type) {
if (type === 'unordered') {
insertText("- ", "");
} else {
insertText("1. ", "");
}
};
window.insertLink = function() {
insertText("[", "](https://)");
};
window.insertImage = function() {
insertText("![", "](https://)");
};
window.insertEmbedVideo = function() {
insertText('<a href="http://www.youtube.com/watch?feature=player_embedded&v=YOUTUBE_VIDEO_ID_HERE" target="_blank"><img src="http://img.youtube.com/vi/YOUTUBE_VIDEO_ID_HERE/0.jpg" alt="IMAGE ALT TEXT HERE" width="1920" height="540" border="10" /></a>', '');
};
window.insertCode = function() {
insertText("```\n", "\n```");
};
window.insertTable = function() {
var tableMarkdown = "\n| Header 1 | Header 2 |\n| ----------- | ----------- |\n| Row 1 Col 1 | Row 1 Col 2 |\n| Row 2 Col 1 | Row 2 Col 2 |\n";
insertText(tableMarkdown, "");
};
window.insertHorizontalRule = function() {
insertText("---\n", "");
};
window.insertFontAwesome = function() {
insertText('<i class="fa-brands fa-markdown"></i>', '');
};
window.insertBoxed = function() {
insertText('<table><td>Text Here</td></table>', '');
};
window.insertSup = function() {
insertText('1<sup>2</sup>', '');
};
window.insertMaterialIcon = function() {
insertText('<i class="material-icons">description</i>', '');
};
window.clearEditor = function() {
editor.setValue("");
};
window.downloadMd = function() {
var markdownText = editor.getValue();
downloadFile("output.md", markdownText);
};
window.downloadHtml = function() {
var markdownText = editor.getValue();
var htmlText = marked.parse(markdownText);
downloadFile("output.html", htmlText);
};
function downloadFile(filename, content) {
var blob = new Blob([content], { type: 'text/plain' });
var link = document.createElement("a");
link.href = URL.createObjectURL(blob);
link.download = filename;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
window.toggleFullScreen = function() {
if (!document.fullscreenElement) {
document.documentElement.requestFullscreen();
} else {
if (document.exitFullscreen) {
document.exitFullscreen();
}
}
};
});
document.getElementById('githubButton').addEventListener('click', function() {
window.open('https://github.com/ufuayk', '_blank');
});