-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
executable file
·106 lines (94 loc) · 2.72 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
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Inkwell</title>
<link href='css/highlight.min.css' rel='stylesheet'>
<style>
#style {
position:absolute;
top:10px;
right:10px;
}
</style>
</head>
<body>
<select id='style'>
<option value='css/gmail.css'>gmail</option>
<option value='css/base/latest/base.css'>base</option>
</select>
<div class='pad2 margin2 col8'></div>
<div id='content' class='prose margin2 pad4 col8'></div>
<script src='js/highlight.min.js'></script>
<script src='js/marked.js'></script>
<script>
var content = document.getElementById('content');
function xhr(url, callback) {
var x = new XMLHttpRequest(),
twoHundred = /^[23]0\d$/;
x.onreadystatechange = function() {
if (4 == x.readyState && 0 !== x.status) {
if (twoHundred.test(x.status)) callback(null, x);
else callback(x, null);
}
};
x.onerror = function(e) { return callback(e, null); };
x.open('GET', url);
x.send();
}
function values(o) {
var v = [];
for (var i in o) if (o.hasOwnProperty(i)) v.push(o[i]);
return v;
}
marked.setOptions({
gfm: true,
tables: true,
breaks: false,
pedantic: false,
sanitize: false,
smartLists: true,
langPrefix: 'language-',
highlight: function (code, lang) {
if (!lang) return code;
// Aliases
if (lang === 'js') lang = 'javascript';
try {
return hljs.highlight(lang, code).value;
} catch(e) {
return hljs.highlightAuto(code).value;
}
}
});
function load(gist) {
var gistUrl = 'https://api.github.com/gists/' + gist;
xhr(gistUrl, function(err, x) {
if (err) return content.innerHTML = 'Error loading Gist';
else var d = JSON.parse(x.responseText);
var c = (values(d.files || {}).filter(function(file) {
return (file.filename.indexOf('.md') !== -1 ||
file.filename.indexOf('.txt') !== -1 ||
file.language === 'Markdown');
})[0] || {}).content;
if (c) content.innerHTML = marked(c);
});
}
function loadHash() {
load(window.location.hash.length > 1 ?
window.location.hash.substr(1) : 'a2bb1ca5d2bbf1dc398d');
}
var style = document.getElementById('style');
function updateStyle() {
var rem = document.head.querySelectorAll('link#custom-style');
for (var i = 0; i < rem.length; i++) document.head.removeChild(rem[i]);
var link = document.head.appendChild(document.createElement('link'));
link.href = this.value;
link.id = 'custom-style';
link.rel = 'stylesheet';
};
style.onchange = updateStyle;
updateStyle.apply(style);
loadHash();
</script>
</body>
</html>