feat(frontend): Markdown 支持 GFM、代码高亮与图片灯箱

统一 SSR/客户端渲染路径,评论与预览共用增强组件。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-16 05:41:25 +08:00
parent f3145b24ff
commit 2056d6a3f9
14 changed files with 1458 additions and 31 deletions

View File

@@ -1,4 +1,5 @@
import ReactMarkdown, { type Components } from "react-markdown";
import type { Components } from "react-markdown";
import { renderMarkdownToReact } from "@/components/markdown/renderMarkdown";
type MarkdownBodyProps = {
content: string;
@@ -6,15 +7,15 @@ type MarkdownBodyProps = {
components?: Components;
};
/** 站点统一 Markdown 渲染:详情页 / 发帖预览共用 prose-content */
export default function MarkdownBody({
/**
* 站点统一 Markdown 渲染(服务端):GFM + Shiki 双主题、图箱、代码块复制/折叠。
* 客户端预览请用 MarkdownBodyClient。
*/
export default async function MarkdownBody({
content,
className = "prose-content",
components,
}: MarkdownBodyProps) {
return (
<div className={className}>
<ReactMarkdown components={components}>{content || ""}</ReactMarkdown>
</div>
);
const tree = await renderMarkdownToReact(content, components);
return <div className={className}>{tree}</div>;
}