bug fixes
This commit is contained in:
parent
b78d4ac439
commit
587a8a8c23
@ -57,6 +57,8 @@
|
|||||||
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
|
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
|
||||||
<script src="js/drag.js"></script>
|
<script src="js/drag.js"></script>
|
||||||
<script src="js/initialize.js"></script>
|
<script src="js/initialize.js"></script>
|
||||||
|
<script src="js/highlight/highlight.min.js"></script>
|
||||||
|
<script src="https://cdn.bootcdn.net/ajax/libs/markdown-it/13.0.1/markdown-it.min.js"></script>
|
||||||
<script src="js/index.js"></script>
|
<script src="js/index.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
40
js/index.js
40
js/index.js
@ -7,12 +7,13 @@ $.ajax({
|
|||||||
var lastIndex = response.length - 1;
|
var lastIndex = response.length - 1;
|
||||||
|
|
||||||
if (response.length <= index) {
|
if (response.length <= index) {
|
||||||
|
message.alert('出错了!', '网络连接出错了,请稍后再试');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
listContent(response, lastIndex);
|
listContent(response, lastIndex);
|
||||||
|
|
||||||
if (response[lastIndex]['type']=='html') {
|
if (response[lastIndex]['type'] == 'html') {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "GET",
|
type: "GET",
|
||||||
url: 'content/html/' + response[lastIndex]['date'] + '.html',
|
url: 'content/html/' + response[lastIndex]['date'] + '.html',
|
||||||
@ -23,6 +24,43 @@ $.ajax({
|
|||||||
message.alert('出错了!', '网络连接出错了,请稍后再试');
|
message.alert('出错了!', '网络连接出错了,请稍后再试');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
$.ajax({
|
||||||
|
type: "GET",
|
||||||
|
url: 'content/md/' + response[lastIndex]['date'] + '.md',
|
||||||
|
success: function (res) {
|
||||||
|
let md = window.markdownit({
|
||||||
|
html: true,
|
||||||
|
breaks: true,
|
||||||
|
highlight: function (str, lang) {
|
||||||
|
if (lang && hljs.getLanguage(lang)) {
|
||||||
|
try {
|
||||||
|
const preCode = hljs.highlight(str, { language: lang }).value;
|
||||||
|
// 以换行进行分割
|
||||||
|
const lines = preCode.split(/\n/).slice(0, -1)
|
||||||
|
// 添加自定义行号
|
||||||
|
let html = lines.map((item, index) => {
|
||||||
|
return '<li><span class="line-num"></span>' + item + '</li>'
|
||||||
|
}).join('')
|
||||||
|
html = '<ol>' + html + '</ol>'
|
||||||
|
// 添加代码语言
|
||||||
|
if (lines.length) {
|
||||||
|
html += '<b class="name">' + lang + '</b>'
|
||||||
|
}
|
||||||
|
return '<pre><code>' +
|
||||||
|
html +
|
||||||
|
'</code></pre>'
|
||||||
|
} catch (e) { }
|
||||||
|
}
|
||||||
|
return ''; // use external default escaping
|
||||||
|
}
|
||||||
|
});
|
||||||
|
appendContent(md.render(res));
|
||||||
|
},
|
||||||
|
error: function () {
|
||||||
|
message.alert('出错了!', '网络连接出错了,请稍后再试');
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
error: function () {
|
error: function () {
|
||||||
|
Loading…
Reference in New Issue
Block a user