-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
124 lines (108 loc) · 2.8 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Baker</title>
<style>
html,
body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
body {
display: flex;
flex-direction: row;
overflow: hidden;
}
#editor {
flex: 1;
}
#separator {
background-color: lightgray;
}
#preview {
background-color: white;
flex: 1;
border: none;
}
</style>
</head>
<body>
<div id="editor"></div>
<div id="separator"></div>
<script>
const $ = require('./assets/jquery.js');
const handleResize = () => {
const columnWidth = ($(window).innerWidth() - 4) / 2;
const columnHeight = $(window).innerHeight();
$('#editor').width(columnWidth).height(columnHeight);
$('#separator').width(4).height(columnHeight);
$('#preview').width(columnWidth).height(columnHeight);
}
$(document).ready(() => {
$(window).resize(() => {
handleResize();
});
handleResize();
});
const server = require('electron').remote.require('./server');
</script>
<script>
// Monaco uses a custom amd loader that over-rides node's require.
// Keep a reference to node's require so we can restore it after executing the amd loader file.
var nodeRequire = global.require;
</script>
<script src="assets/vs/loader.js"></script>
<script>
// Save Monaco's amd require and restore Node's require
var amdRequire = global.require;
global.require = nodeRequire;
</script>
<script>
// require node modules before loader.js comes in
var path = require('path');
function uriFromPath(_path) {
var pathName = path.resolve(_path).replace(/\\/g, '/');
if (pathName.length > 0 && pathName.charAt(0) !== '/') {
pathName = '/' + pathName;
}
return encodeURI('file://' + pathName);
}
amdRequire.config({
baseUrl: uriFromPath(path.join(__dirname, './assets'))
});
// workaround monaco-css not understanding the environment
self.module = undefined;
// workaround monaco-typescript not understanding the environment
self.process.browser = true;
function onDidChangeModelContentDebounced(editor, callback) {
var timer = -1;
var runner = function () {
timer = -1;
callback();
}
return editor.onDidChangeModelContent(function (e) {
if (timer !== -1) {
clearTimeout(timer);
}
timer = setTimeout(runner, 100);
});
}
amdRequire(['vs/editor/editor.main'], function () {
var editor = monaco.editor.create(document.getElementById('editor'), {
value: server.getFileText(),
language: 'markdown',
automaticLayout: true,
wrappingColumn: 0,
lineNumbers: false,
});
onDidChangeModelContentDebounced(editor, () => {
server.setFileText(editor.getValue());
});
});
</script>
<iframe id="preview" src="preview.html" sandbox="allow-scripts allow-same-origin allow-pointer-lock" />
</body>
</html>