2022-09-24 17:28:04 +08:00
|
|
|
(function () {
|
|
|
|
let md = window.markdownit({
|
|
|
|
html: true,
|
2022-09-24 22:32:41 +08:00
|
|
|
breaks: true,
|
2022-09-24 17:28:04 +08:00
|
|
|
highlight: function (str, lang) {
|
|
|
|
if (lang && hljs.getLanguage(lang)) {
|
2022-09-24 22:32:41 +08:00
|
|
|
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) { }
|
2022-09-24 17:28:04 +08:00
|
|
|
}
|
|
|
|
return ''; // use external default escaping
|
|
|
|
}
|
2022-09-24 22:32:41 +08:00
|
|
|
});
|
|
|
|
deployContentList();
|
2022-09-24 17:28:04 +08:00
|
|
|
$.ajax({
|
2022-09-24 22:32:41 +08:00
|
|
|
type: "GET",
|
|
|
|
url: 'content/md/' + getQueryString('date') + '.md?timestamp=' + (new Date().valueOf()),
|
|
|
|
dataType: "text",
|
|
|
|
success: function (response) {
|
2022-09-24 17:28:04 +08:00
|
|
|
|
|
|
|
let res = md.render(response);
|
|
|
|
appendContent(res);
|
2022-09-24 22:56:57 +08:00
|
|
|
loadCss("css/highlight.css");
|
2022-09-24 17:28:04 +08:00
|
|
|
loadCss('js/highlight/styles/atom-one-light.min.css')
|
2022-09-24 22:32:41 +08:00
|
|
|
},
|
|
|
|
error: function () {
|
|
|
|
message.alert('出错了!', '网络连接出错了,请稍后再试');
|
|
|
|
}
|
|
|
|
});
|
2022-09-24 17:28:04 +08:00
|
|
|
})()
|