feat(评论): 添加Markdown渲染和样式支持

- 引入marked和xss库处理评论内容的Markdown渲染和XSS过滤
- 添加CSS样式支持评论内容的标题、列表、代码块等Markdown元素显示
This commit is contained in:
anghunk
2026-01-20 13:19:10 +08:00
parent b11abca96d
commit e826b7cbef
3 changed files with 102 additions and 4 deletions

View File

@@ -1,5 +1,7 @@
import { Context } from 'hono';
import { UAParser } from 'ua-parser-js';
import { marked } from 'marked';
import xss from 'xss';
import { Bindings } from '../../bindings';
import {
sendCommentNotification,
@@ -67,11 +69,12 @@ export const postComment = async (c: Context<{ Bindings: Bindings }>) => {
`).run();
// 3. 准备数据
const contentText = checkContent(rawContent);
const cleanedContent = checkContent(rawContent);
const contentText = cleanedContent;
const author = checkContent(rawAuthor);
// Markdown 渲染与 XSS 过滤
const html = await marked.parse(rawContent, { async: true });
const html = await marked.parse(cleanedContent, { async: true });
const contentHtml = xss(html, {
whiteList: {
...xss.whiteList,