feat: 共享 markdown 渲染器,完整语法支持
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
<script src="/static/lib/diff2html.min.js"></script>
|
||||
<script src="/static/lib/highlight.min.js"></script>
|
||||
<script src="/static/js/sse.js"></script>
|
||||
<script src="/static/js/markdown.js"></script>
|
||||
<script src="/static/js/diff-viewer.js"></script>
|
||||
<script src="/static/js/review-inline.js"></script>
|
||||
<script src="/static/js/note-editor.js"></script>
|
||||
@@ -418,28 +419,9 @@
|
||||
btn.textContent = diffVisible ? '隐藏 Diff' : '显示 Diff';
|
||||
}
|
||||
|
||||
// Simple markdown rendering
|
||||
// Markdown rendering (delegates to shared Markdown.render)
|
||||
function renderMarkdown(text) {
|
||||
if (!text) return '';
|
||||
let html = text
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/^### (.+)$/gm, '<h3>$1</h3>')
|
||||
.replace(/^## (.+)$/gm, '<h2>$1</h2>')
|
||||
.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 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;
|
||||
return Markdown.render(text);
|
||||
}
|
||||
|
||||
// ── History loading ────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user