diff --git a/js/post.js b/js/post.js index 25aeef2..c9b1c1f 100644 --- a/js/post.js +++ b/js/post.js @@ -54,19 +54,34 @@ async function renderPostDetail(postId) { imagesHtml += ''; } + // Markdown 渲染(安全处理) + let renderedContent = post.content || ''; + try { + if (typeof marked !== 'undefined' && marked.parse) { + renderedContent = marked.parse(renderedContent); + } else { + renderedContent = renderedContent.replace(/\n/g, '
'); + } + } catch (e) { + renderedContent = renderedContent.replace(/\n/g, '
'); + } + let html = `
${username} ${time} - ${currentUser && currentUser.id === post.user_id ? `` : ''} + ${post.edited_at ? `(已编辑 ${new Date(post.edited_at).toLocaleString('zh-CN')})` : ''} +
+ ${currentUser && currentUser.id === post.user_id ? `` : ''} + ${currentUser && currentUser.id === post.user_id ? `` : ''} +
-
${post.title || '无标题'}
-
${(post.content || '').replace(/\n/g, '
')}
+
${renderedContent}
${imagesHtml}
@@ -110,6 +125,17 @@ async function renderPostDetail(postId) { document.getElementById('replyCaptchaInput').value = ''; refreshCaptcha('reply'); + // 编辑按钮 + const editBtn = document.getElementById('editPostBtn'); + if (editBtn) { + editBtn.addEventListener('click', function() { + const postId = this.dataset.postid; + const currentTitle = post.title || ''; + const currentContent = post.content || ''; + openEditModal(postId, currentTitle, currentContent); + }); + } + const deleteBtn = document.getElementById('detailDeleteBtn'); if (deleteBtn) { deleteBtn.addEventListener('click', function() {