优化项目结构

This commit is contained in:
2026-05-06 18:25:44 +08:00
parent 01594dba7a
commit bdedf1a0cf
21 changed files with 7 additions and 9 deletions

View File

@@ -0,0 +1,34 @@
const MarkdownRenderer = {
init() {
// 配置 marked.js
marked.setOptions({
highlight: function(code, lang) {
if (lang && hljs.getLanguage(lang)) {
return hljs.highlight(code, { language: lang }).value;
}
return hljs.highlightAuto(code).value;
},
breaks: true,
gfm: true
});
},
render(text) {
if (!text) return '';
let html = marked.parse(text);
// 为代码块添加复制按钮
html = html.replace(/<pre><code/g, '<pre><button class="copy-btn" onclick="MarkdownRenderer.copyCode(this)">复制</button><code');
return html;
},
copyCode(btn) {
const code = btn.nextElementSibling;
navigator.clipboard.writeText(code.textContent).then(() => {
btn.textContent = '已复制';
setTimeout(() => { btn.textContent = '复制'; }, 2000);
});
}
};
// 初始化
MarkdownRenderer.init();