feat: markdown rendering + dark mode input fixes + DM icon align

- Add marked dependency; render post/reply content and signature via
  marked.parse (matches upstream). lib/markdown.js helper + CSS for
  code/pre/blockquote/tables in glass theme
- Fix hardcoded #e2e8f0 white inputs in dark mode: NewPost title/content,
  Modals report select, ReplyList, AdminForumSettings/Links/Users/Logs
- DM button: replace ✉️ emoji with upstream SVG chat bubble icon
This commit is contained in:
lezi-fun committed 2026-08-10 18:18:19 +08:00
1 parent bd6314be38
commit 1a8a588d60
14 files changed
+98 -22

No files matched your search

+62
View File
@@ -1978,3 +1978,65 @@ a.btn-secondary {
from { opacity: 0; }
to { opacity: 1; }
}
/* ===== Markdown 渲染样式 ===== */
.post-content code,
.reply-content code {
background: rgba(91, 155, 213, 0.12);
padding: 2px 6px;
border-radius: 4px;
font-size: 0.9em;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
color: var(--glass-text);
}
.post-content pre {
background: rgba(15, 15, 26, 0.75);
border: 1px solid var(--glass-border);
border-radius: var(--radius-sm);
padding: 12px 14px;
overflow-x: auto;
margin: 10px 0;
}
.post-content pre code {
background: none;
padding: 0;
color: #e8e8f0;
}
.post-content blockquote {
border-left: 3px solid var(--primary);
margin: 10px 0;
padding: 4px 14px;
color: var(--glass-text-secondary);
background: rgba(91, 155, 213, 0.08);
border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.post-content img {
max-width: 100%;
border-radius: var(--radius-sm);
}
.post-content ul,
.post-content ol {
padding-left: 24px;
margin: 8px 0;
}
.post-content table {
border-collapse: collapse;
margin: 10px 0;
}
.post-content th,
.post-content td {
border: 1px solid var(--glass-border);
padding: 6px 12px;
}
.post-content h1,
.post-content h2,
.post-content h3,
.post-content h4 {
margin: 14px 0 8px;
color: var(--glass-text);
}
.post-content hr {
border: none;
border-top: 1px solid var(--glass-border);
margin: 14px 0;
}
+3
View File
@@ -8,6 +8,7 @@
"aws4fetch": "^1.0.20",
"bcryptjs": "^3.0.3",
"jsonwebtoken": "^9.0.2",
"marked": "^18.0.9",
"next": "^14.2.15",
"pg": "^8.11.3",
"react": "^18.3.1",
@@ -80,6 +81,8 @@
"loose-envify": ["loose-envify@1.4.0", "https://registry.npmmirror.com/loose-envify/-/loose-envify-1.4.0.tgz", { "dependencies": { "js-tokens": "^3.0.0 || ^4.0.0" }, "bin": "cli.js" }, "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q=="],
"marked": ["marked@18.0.9", "https://registry.npmmirror.com/marked/-/marked-18.0.9.tgz", { "bin": { "marked": "bin/marked.js" } }, "sha512-/Sa4qiiHZxf0/FQdBBowr9q4r10krCwMvpK48FUBdXdUXScDxiQGR9zCPrFgRVR5LU3iySOiIjy09ZQvADir1w=="],
"ms": ["ms@2.1.3", "https://registry.npmmirror.com/ms/-/ms-2.1.3.tgz", {}, "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA=="],
"nanoid": ["nanoid@3.3.18", "https://registry.npmmirror.com/nanoid/-/nanoid-3.3.18.tgz", { "bin": "bin/nanoid.cjs" }, "sha512-DTg4MJbGMWkfi6VZFdNt2/caMbQy4Ou+Op/hJQvGEWcnVfoA1QA+xzRKAzw9jD6+GVOOeYr/mIcuDSdug6F6+w=="],
+2 -1
View File
@@ -6,6 +6,7 @@ import { API } from '@/lib/api';
import { useApp } from './AppProvider';
import { Icon } from './Icons';
import ImageViewer from './ImageViewer';
import { renderMarkdown } from '@/lib/markdown';
function avatar(username) {
return 'https://ui-avatars.com/api/?name=' + encodeURIComponent(username || '匿名用户') +
@@ -99,7 +100,7 @@ export default function Feed({ onOpenModal, onReport }) {
)}
</div>
<div className="post-title">{p.title || '无标题'}</div>
<div className="post-content">{(p.content || '').split('\n').map((l, i) => <span key={i}>{l}<br /></span>)}</div>
<div className="post-content" dangerouslySetInnerHTML={{ __html: renderMarkdown(p.content) }} />
{p.images && p.images.length > 0 && (
<div className="post-images">
{p.images.map((img, i) => (
+1 -1
View File
@@ -124,7 +124,7 @@ export default function Modals({ modal, onClose, reportPostId }) {
<h2 style={{ marginBottom: 16 }}><Icon name="shieldAlert" size={20} /> 举报帖子</h2>
<p style={{ fontSize: 14, color: '#64748b', marginBottom: 12 }}>请选择举报原因:</p>
<select
style={{ width: '100%', padding: '8px 12px', border: '1px solid #e2e8f0', borderRadius: 4, marginBottom: 16 }}
style={{ width: '100%', padding: '8px 12px', border: '1px solid var(--border)', borderRadius: 4, marginBottom: 16, background: 'var(--bg)', color: 'var(--text)' }}
value={reportReason}
onChange={(e) => setReportReason(e.target.value)}
>
+2 -2
View File
@@ -88,14 +88,14 @@ export default function NewPost() {
<input
type="text"
placeholder="标题"
style={{ width: '100%', padding: '10px 14px', border: '1.5px solid #e2e8f0', borderRadius: 6, fontSize: 15, fontWeight: 600, marginBottom: 12, fontFamily: 'inherit' }}
style={{ width: '100%', padding: '10px 14px', border: '1.5px solid var(--border)', borderRadius: 6, fontSize: 15, fontWeight: 600, marginBottom: 12, fontFamily: 'inherit', background: 'var(--bg)', color: 'var(--text)' }}
value={title}
onChange={(e) => setTitle(e.target.value)}
/>
<textarea
rows={6}
placeholder="说点什么..."
style={{ width: '100%', padding: 12, border: '1.5px solid #e2e8f0', borderRadius: 6, fontSize: 15, fontFamily: 'inherit', resize: 'vertical' }}
style={{ width: '100%', padding: 12, border: '1.5px solid var(--border)', borderRadius: 6, fontSize: 15, fontFamily: 'inherit', resize: 'vertical', background: 'var(--bg)', color: 'var(--text)' }}
value={content}
onChange={(e) => setContent(e.target.value)}
/>
+3 -6
View File
@@ -7,6 +7,7 @@ import { useApp } from './AppProvider';
import ReplyList from './ReplyList';
import { Icon } from './Icons';
import ImageViewer from './ImageViewer';
import { renderMarkdown } from '@/lib/markdown';
function avatar(username) {
return 'https://ui-avatars.com/api/?name=' + encodeURIComponent(username || '匿名用户') +
@@ -155,9 +156,7 @@ export default function PostDetail({ postId }) {
)}
</div>
</div>
<div className="post-content" style={{ fontSize: 16, lineHeight: 1.8 }}>
{(post.content || '').split('\n').map((l, i) => <span key={i}>{l}<br /></span>)}
</div>
<div className="post-content" style={{ fontSize: 16, lineHeight: 1.8 }} dangerouslySetInnerHTML={{ __html: renderMarkdown(post.content) }} />
{post.images && post.images.length > 0 && (
<div className="post-images">
{post.images.map((img, i) => (
@@ -166,9 +165,7 @@ export default function PostDetail({ postId }) {
</div>
)}
{post.signature && (
<div style={{ marginTop: 16, paddingTop: 12, borderTop: '1px solid var(--border-light)', fontSize: 12, color: 'var(--text-secondary)' }}>
{post.signature}
</div>
<div style={{ marginTop: 16, paddingTop: 12, borderTop: '1px solid var(--border-light)', fontSize: 12, color: 'var(--text-secondary)' }} dangerouslySetInnerHTML={{ __html: renderMarkdown(post.signature) }} />
)}
</div>
<ReplyList postId={postId} onRefresh={load} />
+4 -5
View File
@@ -5,6 +5,7 @@ import { useEffect, useState, useCallback } from 'react';
import { API, generateCaptcha } from '@/lib/api';
import { useApp } from './AppProvider';
import { Icon } from './Icons';
import { renderMarkdown } from '@/lib/markdown';
function avatar(username) {
return 'https://ui-avatars.com/api/?name=' + encodeURIComponent(username || '匿名用户') +
@@ -89,21 +90,19 @@ export default function ReplyList({ postId, onRefresh }) {
</button>
)}
</div>
<div className="reply-content">
{(r.content || '').split('\n').map((l, i) => <span key={i}>{l}<br /></span>)}
</div>
<div className="reply-content" dangerouslySetInnerHTML={{ __html: renderMarkdown(r.content) }} />
</div>
);
})
)}
</div>
<div id="replyArea" style={{ marginTop: 24, borderTop: '1px solid #e2e8f0', paddingTop: 20 }}>
<div id="replyArea" style={{ marginTop: 24, borderTop: '1px solid var(--border)', paddingTop: 20 }}>
<h3 style={{ fontSize: 16, marginBottom: 12 }}><Icon name="message" size={16} /> 发表回复</h3>
<textarea
rows={3}
placeholder="写下你的回复..."
style={{ width: '100%', padding: '10px 12px', border: '1px solid #e2e8f0', borderRadius: 4, fontSize: 14, fontFamily: 'inherit', resize: 'vertical' }}
style={{ width: '100%', padding: '10px 12px', border: '1px solid var(--border)', borderRadius: 4, fontSize: 14, fontFamily: 'inherit', resize: 'vertical', background: 'var(--bg)', color: 'var(--text)' }}
value={content}
onChange={(e) => setContent(e.target.value)}
onKeyDown={(e) => { if (e.key === 'Enter' && (e.ctrlKey || e.metaKey)) handleSubmit(); }}
+1 -1
View File
@@ -36,7 +36,7 @@ export default function AdminForumSettings() {
<label style={{ fontWeight: 600, fontSize: 14, display: 'block', marginBottom: 6 }}>论坛名称</label>
<input
type="text"
style={{ width: '100%', padding: '10px 14px', border: '1.5px solid #e2e8f0', borderRadius: 6, fontSize: 15, marginBottom: 12, fontFamily: 'inherit' }}
style={{ width: '100%', padding: '10px 14px', border: '1.5px solid var(--border)', borderRadius: 6, fontSize: 15, marginBottom: 12, fontFamily: 'inherit', background: 'var(--bg)', color: 'var(--text)' }}
value={name}
onChange={(e) => setName(e.target.value)}
/>
+2 -2
View File
@@ -40,12 +40,12 @@ export default function AdminLinks() {
<div style={{ marginBottom: 16, display: 'flex', gap: 8, flexWrap: 'wrap' }}>
<input
type="text" placeholder="链接名称"
style={{ flex: 1, minWidth: 120, padding: '8px 12px', border: '1px solid #e2e8f0', borderRadius: 4 }}
style={{ flex: 1, minWidth: 120, padding: '8px 12px', border: '1px solid var(--border)', borderRadius: 4, background: 'var(--bg)', color: 'var(--text)' }}
value={title} onChange={(e) => setTitle(e.target.value)}
/>
<input
type="url" placeholder="链接地址"
style={{ flex: 2, minWidth: 160, padding: '8px 12px', border: '1px solid #e2e8f0', borderRadius: 4 }}
style={{ flex: 2, minWidth: 160, padding: '8px 12px', border: '1px solid var(--border)', borderRadius: 4, background: 'var(--bg)', color: 'var(--text)' }}
value={url} onChange={(e) => setUrl(e.target.value)}
/>
<button className="btn-primary" style={{ padding: '8px 16px' }} onClick={handleAdd}>添加</button>
+1 -1
View File
@@ -23,7 +23,7 @@ export default function AdminLogs() {
return (
<table style={{ width: '100%', borderCollapse: 'collapse', fontSize: 13 }}>
<thead>
<tr style={{ textAlign: 'left', borderBottom: '1px solid #e2e8f0' }}>
<tr style={{ textAlign: 'left', borderBottom: '1px solid var(--border)' }}>
<th>时间</th><th>用户</th><th>操作</th>
</tr>
</thead>
+2 -2
View File
@@ -38,7 +38,7 @@ export default function AdminUsers() {
<div style={{ overflowX: 'auto' }}>
<table style={{ width: '100%', borderCollapse: 'collapse', fontSize: 14 }}>
<thead>
<tr style={{ textAlign: 'left', borderBottom: '2px solid #e2e8f0' }}>
<tr style={{ textAlign: 'left', borderBottom: '2px solid var(--border)' }}>
<th style={{ padding: '10px 12px' }}>用户</th>
<th style={{ padding: '10px 12px' }}>角色</th>
<th style={{ padding: '10px 12px' }}>注册时间</th>
@@ -65,7 +65,7 @@ export default function AdminUsers() {
<td style={{ padding: '10px 12px' }}>
<span style={{
display: 'inline-block', padding: '2px 10px', borderRadius: 4, fontSize: 12, fontWeight: 500,
...(isAdmin ? { background: '#6366f1', color: '#fff' } : { background: '#e2e8f0', color: '#64748b' }),
...(isAdmin ? { background: '#6366f1', color: '#fff' } : { background: 'var(--border)', color: 'var(--text-secondary)' }),
}}>
{isAdmin ? '管理员' : '普通用户'}
</span>
+2 -1
View File
@@ -4,6 +4,7 @@
import { useState, useEffect, useCallback } from 'react';
import { API } from '@/lib/api';
import { useApp } from '../AppProvider';
import { Icon } from '../Icons';
import ConversationList from './ConversationList';
import ChatWindow from './ChatWindow';
@@ -33,7 +34,7 @@ export function DMButton() {
style={{ position: 'relative', padding: '6px 8px', background: 'none', border: 'none', cursor: 'pointer', color: 'var(--text-secondary)', borderRadius: 4, display: 'inline-flex', alignItems: 'center', justifyContent: 'center' }}
onClick={() => window.dispatchEvent(new CustomEvent('forumlify-open-messages'))}
>
✉️
<Icon name="message" size={20} />
{unread > 0 && (
<span style={{ position: 'absolute', top: -2, right: -2, background: '#ef4444', color: '#fff', borderRadius: '50%', padding: '2px 6px', fontSize: 10, fontWeight: 600, minWidth: 18, textAlign: 'center', lineHeight: 1.4 }}>
{unread > 99 ? '99+' : unread}
+12
View File
@@ -0,0 +1,12 @@
// Markdown 渲染工具(对齐上游 marked 行为)
import { marked } from 'marked';
// 渲染 markdown 为 HTML;失败时回退为纯文本换行
export function renderMarkdown(text) {
if (!text) return '';
try {
return marked.parse(text);
} catch {
return text.replace(/\n/g, '<br>');
}
}
+1
View File
@@ -13,6 +13,7 @@
"aws4fetch": "^1.0.20",
"bcryptjs": "^3.0.3",
"jsonwebtoken": "^9.0.2",
"marked": "^18.0.9",
"next": "^14.2.15",
"pg": "^8.11.3",
"react": "^18.3.1",