From 587a8a8c23abba20566eee04cab4224d1c41aaf8 Mon Sep 17 00:00:00 2001 From: wcx <2738076308@qq.com> Date: Sat, 24 Sep 2022 22:47:02 +0800 Subject: [PATCH] bug fixes --- index.html | 2 ++ js/index.js | 40 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 340fae2..1dcf213 100644 --- a/index.html +++ b/index.html @@ -57,6 +57,8 @@ + + diff --git a/js/index.js b/js/index.js index 60aa7cc..b7db9c3 100644 --- a/js/index.js +++ b/js/index.js @@ -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 '
  • ' + item + '
  • ' + }).join('') + html = '
      ' + html + '
    ' + // 添加代码语言 + if (lines.length) { + html += '' + lang + '' + } + return '
    ' +
    +										html +
    +										'
    ' + } catch (e) { } + } + return ''; // use external default escaping + } + }); + appendContent(md.render(res)); + }, + error: function () { + message.alert('出错了!', '网络连接出错了,请稍后再试'); + } + }); } }, error: function () {