-
Notifications
You must be signed in to change notification settings - Fork 0
/
preview.html
82 lines (71 loc) · 2.01 KB
/
preview.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
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Markdown Viewer</title>
<link rel="stylesheet" href="assets/style.css">
<script type="text/javascript" src="assets/libs.js"></script>
</head>
<body>
<div style="margin-left:10%; width:80%">
<div id="content" class="markdown-body"></div>
</div>
<script>
// Initilize Makrded.js Renderer
var renderer = new marked.Renderer();
let getImagePath = (x) => x
// enable resize option for images
renderer.image = function (href, title, text) {
href = getImagePath(href);
var tags = '';
if (title) {
size = title.split('x');
if (size[1])
tags = 'width=' + size[0] + ' height=' + size[1];
else
tags = 'width=' + size[0];
} else if (href && href.indexOf('=') != -1) {
size = href.split('=')[1].split('x');
href = href.split('=')[0];
if (size[1])
tags = 'width=' + size[0] + ' height=' + size[1];
else
tags = 'width=' + size[0];
}
return ('<img src="' + href + '" alt="' + text + '" ' + tags + '>');
};
// remove trailing newline in code blocks
renderer.code = function (code, language) {
return ('<pre><code>' + code + '</code></pre>');
};
// global options
marked.setOptions({
renderer: renderer,
gfm: true,
tables: true,
breaks: false,
pedantic: false,
sanitize: false,
smartLists: true,
smartypants: false
});
function setPreviewText(text) {
document.getElementById('content').innerHTML = marked(text);
renderMathInElement(document.getElementById('content'));
}
const server = top.require('electron').remote.require('./server');
const path = top.require('path');
function updatePreview(text) {
const filePath = server.getFilePath();
const basePath = path.dirname(filePath);
getImagePath = (imagePath) => 'file://' + path.join(basePath, imagePath);
console.log(getImagePath('x.png'));
setPreviewText(server.getFileText());
}
server.setFileTextListener(() => {
updatePreview();
});
updatePreview();
</script>
</body>
</html>