bug fixes

This commit is contained in:
wcx 2022-09-24 22:47:02 +08:00
parent b78d4ac439
commit 587a8a8c23
2 changed files with 41 additions and 1 deletions

View File

@ -57,6 +57,8 @@
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<script src="js/drag.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>
</body>

View File

@ -7,12 +7,13 @@ $.ajax({
var lastIndex = response.length - 1;
if (response.length <= index) {
message.alert('出错了!', '网络连接出错了,请稍后再试');
return;
}
listContent(response, lastIndex);
if (response[lastIndex]['type']=='html') {
if (response[lastIndex]['type'] == 'html') {
$.ajax({
type: "GET",
url: 'content/html/' + response[lastIndex]['date'] + '.html',
@ -23,6 +24,43 @@ $.ajax({
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 () {