-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
101 lines (90 loc) · 2.48 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta
http-equiv="Content-Security-Policy"
content="script-src 'self' 'unsafe-inline';"
/>
<title>Markdown-editor</title>
<link
rel="stylesheet"
href="./node_modules/simplemde/dist/simplemde.min.css"
/>
<script src="./node_modules/simplemde/dist/simplemde.min.js"></script>
<style>
html,
body {
height: 100%;
display: flex;
flex: 1;
flex-direction: column;
}
.CodeMirror {
flex: 1;
}
#editor {
top: 0px;
left: 0px;
height: 100%;
width: 100%;
position: absolute;
}
</style>
</head>
<body ondrop="dropHandler(event);">
<textarea id="editor"></textarea>
<script>
var editor = new SimpleMDE({
element: document.getElementById('editor'),
hideIcons: ['guide','fullscreen']
});
const { ipcRenderer } = require('electron');
ipcRenderer.on('editor-event', (event, arg) => {
console.log(arg);
event.sender.send('editor-reply', `Received ${arg}`);
if (arg === 'toggle-bold') {
editor.toggleBold();
}
if (arg === 'toggle-italic') {
editor.toggleItalic();
}
if (arg === 'toggle-heading') {
editor.toggleHeading1();
}
if (arg === 'toggle-Strikethough') {
editor.toggleStrikethrough();
}
if (arg === 'save') {
event.sender.send('save', editor.value());
}
if(arg === 'new') {
editor.value("");
}
});
ipcRenderer.on('load', (event, content) => {
if (content) {
editor.value(content);
}
});
ipcRenderer.send('editor-reply', 'Page Loaded');
function dropHandler(event) {
event.preventDefault();
if (event.dataTransfer.items) {
if (event.dataTransfer.items[0].kind === 'file') {
var file = event.dataTransfer.items[0].getAsFile();
if (file.type === 'text/markdown') {
var reader = new FileReader();
reader.onload = e => {
// console.log(e.target.result);
editor.codemirror.setValue(e.target.result);
};
reader.readAsText(file);
}
}
}
}
</script>
</body>
</html>