-
Notifications
You must be signed in to change notification settings - Fork 2
/
read-md.html
73 lines (49 loc) · 1.91 KB
/
read-md.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
<!doctype html>
<html lang=en >
<head>
<meta charset=utf-8 >
<title>Open Index or Markdown</title>
<meta name=viewport content='width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no' >
<meta name=description content='File wrangler. Default index.html file. Opens HTML or Markdown files. Passes location.hash.' >
<meta name=keywords content='ShowDown,Markdown,AJAX,JavaScript,HTML,CSS,GitHub,FOSS' >
<meta name=date content='2017-03-25' >
</head>
<body>
<script src=https://cdn.rawgit.com/showdownjs/showdown/master/dist/showdown.min.js ></script>
<script>
// https://github.com/showdownjs/showdown
// https://github.com/jaanga/jaanga.github.io/tree/master/cookbook-html/templates2/open-index-or-markdown
var defaultFile = 'read-md.html';
location.hash = 'README.md';
var contents;
init();
function init() {
if ( location.hash.match( '.md' ) ) {
onHashChange();
} else {
window.location.href = defaultFile + location.hash;
}
}
function onHashChange() {
var css, converter, url, xhr;
css = document.head.appendChild( document.createElement( 'style' ) );
css.innerHTML =
'body { font: 12pt monospace; left: 0; margin: 0 auto; max-width: 800px; right: 0; }' +
'a { color: crimson; text-decoration: none; }' +
'a:hover { text-decoration: underline; }' +
'button, input[type=button] { background-color: #eee; border: 2px #eee solid; color: #888; }' +
'';
contents = contents ? contents : document.body.appendChild( document.createElement( 'div' ) ) ;
showdown.setFlavor('github');
converter = new showdown.Converter();
url = location.hash.slice( 1 );
xhr = new XMLHttpRequest();
xhr.open( 'get', url, true );
xhr.onload = function() { contents.innerHTML = converter.makeHtml( xhr.responseText ); };
xhr.send( null );
document.title = url.split( '/' ).pop();
window.addEventListener( 'hashchange', onHashChange, false );
}
</script>
</body>
</html>