feat: wangEditor 替换为 ByteMD Markdown 编辑器

- 移除 wangEditor 5 库文件(1.27MB JS + 14KB CSS,含手动 hack)
- 集成 ByteMD 1.22.0(基于 CodeMirror 5,不依赖 contentEditable)
- 编辑器输出 Markdown 原文,后端 goldmark + bluemonday 双重防护渲染 HTML
- 删除 editor.js 中 scrollIntoView hack、code-lang-label DOM 注入、PreviewAPI 调用
- 清理 posts.css 中 ~200 行 wangEditor 样式覆盖(w-e-* 类名)
- 清理 show.html 中 code-lang-label JS 注入(goldmark 自带 language-xxx class)
- 更新 CSP 安全策略:移除 CodeMirror 注释,保留 esm.sh CDN
- go.mod:bluemonday 和 goldmark 均保留为直接依赖(纵深防御)
This commit is contained in:
2026-05-28 02:16:50 +08:00
parent 804fd50edf
commit 22a302315a
9 changed files with 222 additions and 24906 deletions

View File

@ -9,13 +9,14 @@ import (
func SecurityHeaders() gin.HandlerFunc {
return func(c *gin.Context) {
// Content-Security-Policy
// script-src: 本站 + esm.sh CDN (CodeMirror 6 ESM 模块)
// script-src: 本站 + esm.sh CDN (ByteMD ESM 模块)
// style-src: 本站 + esm.sh (ByteMD/highlight.js CSS)
// connect-src: 本站 + esm.sh (source map 请求)
// img-src: 本站 + data: URI (头像裁切) + blob: (粘贴图片)
c.Header("Content-Security-Policy",
"default-src 'self'; "+
"script-src 'self' 'unsafe-inline' https://esm.sh; "+
"style-src 'self' 'unsafe-inline'; "+
"style-src 'self' 'unsafe-inline' https://esm.sh; "+
"img-src 'self' data: blob:; "+
"connect-src 'self' https://esm.sh")