-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmd.html
84 lines (70 loc) · 2.84 KB
/
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
74
75
76
77
78
79
80
81
82
83
84
<!DOCTYPE html>
<html lang="en">
<script src="/static/baidu.js"></script>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<title>Page - chengbw</title>
<link rel="stylesheet" href="static/md.v0.2.css">
<link rel="stylesheet" href="static/cc.v0.1.css">
<script src="https://cdn.bootcss.com/axios/0.18.0/axios.js"></script>
<script src="https://cdn.bootcss.com/markdown-it/8.4.2/markdown-it.min.js"></script>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/styles/default.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/highlight.min.js"></script>
</head>
<body>
<div class="header">
<div class="menu-item"><a href="/index.html">Index</a></div>
<div class="menu-item"><a href="/about.html">About</a></div>
</div>
<div class="loader" id="id-loader"></div>
<div class="content-wrap">
<div id="id-content" class="md"></div>
</div>
<script>
"use strict";
let md = window.markdownit({
highlight: function (str, lang) {
if (lang && hljs.getLanguage(lang)) {
try {
return '<pre class="hljs"><code>' +
hljs.highlight(lang, str, true).value +
'</code></pre>';
} catch (__) { }
}
return '<pre class="hljs"><code>' + md.utils.escapeHtml(str) + '</code></pre>';
}
});
//get data
let timestamp = (new Date()).getUTCMilliseconds();
let url = new URL(window.location.href);
let src = url.searchParams.get("src") + "?timestamp=" + timestamp; //为了每次都取到最新的数据,所以加上timestamp
axios.get(src)
.then(function (response) {
// console.log(response.data);
//display content
document.getElementById('id-content').innerHTML = parse_md(response.data);
set_title(response.data);
stop_show_loader();
}).catch(function (error) {
console.log(error);
stop_show_loader();
});
function set_title(text) {
let title = text.split('\n')[0].trim();
if (title.substr(0, 2) == '# ') {
document.title = title.replace('# ','') + ' - chengbw';
}
}
function parse_md(text) {
let result = md.render(text);
return result;
}
function stop_show_loader() {
document.getElementById('id-loader').style.display = "none";
}
</script>
</body>
</html>