-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
preview.html
69 lines (61 loc) · 1.63 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
<article id="markdown-body">
<div>%s</div>
</article>
%s
<script> hljs.initHighlightingOnLoad(); </script>
<script>
showdown.extension('codehighlight', function() {
function htmlunencode(text) {
return (
text
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
);
}
return [
{
type: 'output',
filter: function (text, converter, options) {
// use new shodown's regexp engine to conditionally parse codeblocks
var left = '<pre><code\\b[^>]*>',
right = '</code></pre>',
flags = 'g',
replacement = function (wholeMatch, match, left, right) {
// unescape match to prevent double escaping
match = htmlunencode(match);
return left + hljs.highlightAuto(match).value + right;
};
return showdown.helper.replaceRecursiveRegExp(text, replacement, left, right, flags);
}
}
];
});
</script>
<script>
function display() {
showdown.setFlavor('%s');
let converter = new showdown.Converter({ extensions: ['codehighlight'] });
converter.setOption('simpleLineBreaks', false);
converter.setOption('tables', true);
let md = document.querySelector('#markdown-body div');
if (!md) return;
let text = md.innerHTML;
let newHTML = converter.makeHtml(text);
md.innerHTML = newHTML;
}
display();
</script>
%s
<style>
body {
background-color: %s;
}
#markdown-body {
background-color: %s;
border: 2px solid %s;
width: 800px;
margin: auto;
padding: 2%% 5%%;
}
</style>