fix: 改进 diff 查看器样式和 markdown 渲染

This commit is contained in:
2026-06-19 21:41:47 +08:00
parent 987f331474
commit 1cfab2d2d1
5 changed files with 136 additions and 11 deletions
+9 -4
View File
@@ -216,10 +216,15 @@
.replace(/^# (.+)$/gm, '<h1>$1</h1>')
.replace(/\*\*(.+?)\*\*/g, '<strong>$1</strong>')
.replace(/`(.+?)`/g, '<code class="bg-gray-100 px-1 rounded">$1</code>')
.replace(/^- (.+)$/gm, '<li>$1</li>')
.replace(/\n/g, '<br>');
// Wrap consecutive <li> in <ul>
html = html.replace(/(<li>.*?<\/li>)(\s*<br>\s*<li>)/g, '$1$2');
.replace(/^- (.+)$/gm, '<li class="bullet-item">$1</li>')
.replace(/^(\d+)\. (.+)$/gm, '<li class="numbered-item">$2</li>')
.replace(/\n/g, '\n');
// Wrap consecutive bullet <li> in <ul>
html = html.replace(/((?:<li class="bullet-item">.*<\/li>\n?)+)/g, '<ul>$1</ul>');
// Wrap consecutive numbered <li> in <ol>
html = html.replace(/((?:<li class="numbered-item">.*<\/li>\n?)+)/g, '<ol>$1</ol>');
// Convert remaining newlines to <br> (outside lists)
html = html.replace(/\n/g, '<br>');
return html;
}
+11 -4
View File
@@ -303,7 +303,7 @@
// Simple markdown rendering
function renderMarkdown(text) {
if (!text) return '';
return text
let html = text
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
@@ -312,9 +312,16 @@
.replace(/^# (.+)$/gm, '<h1>$1</h1>')
.replace(/\*\*(.+?)\*\*/g, '<strong>$1</strong>')
.replace(/`(.+?)`/g, '<code class="bg-gray-100 px-1 rounded">$1</code>')
.replace(/^- (.+)$/gm, '<li>$1</li>')
.replace(/(\d+)\. (.+)$/gm, '<li>$1. $2</li>')
.replace(/\n/g, '<br>');
.replace(/^- (.+)$/gm, '<li class="bullet-item">$1</li>')
.replace(/^(\d+)\. (.+)$/gm, '<li class="numbered-item">$2</li>')
.replace(/\n/g, '\n');
// Wrap consecutive bullet <li> in <ul>
html = html.replace(/((?:<li class="bullet-item">.*<\/li>\n?)+)/g, '<ul>$1</ul>');
// Wrap consecutive numbered <li> in <ol>
html = html.replace(/((?:<li class="numbered-item">.*<\/li>\n?)+)/g, '<ol>$1</ol>');
// Convert remaining newlines to <br> (outside lists)
html = html.replace(/\n/g, '<br>');
return html;
}
loadRefs();