- Add shared BlogMD renderer (static/js/markdown.js): marked + DOMPurify
+ highlight.js pipeline with GFM support, heading id slugger with
CJK-aware anchors, syntax highlighting, per-block copy button and
language badge, lazy images with lightbox, external links opened
safely in new tabs, tables wrapped for small screens.
- Add .md-body typography styles (static/css/markdown.css) so articles,
comments and editor previews render with proper headings, tables,
lists, blockquotes and code blocks (previously the prose classes had
no effect because the Tailwind typography plugin is not loaded).
- Fix marked options that were set after parsing and removed from
marked v4+ (mangle/headerIds no-ops).
- Pin CDN versions (marked 15.0.12, dompurify 3.4.13, highlight.js
11.12.0) instead of floating 'latest' URLs.
- Wire EasyMDE preview/side-by-side to BlogMD in admin and user
article editors; use BlogMD for comment bodies on the article page,
admin comment list and comment preview.
- Serve /static in main.go and deploy it in install_linux.sh.
kevin
merged commit 5f21c73044 into main2026-08-18 18:12:12 +08:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
概述
完善前端 Markdown 渲染能力:文章正文、评论、后台评论列表、编辑器预览统一走一套增强渲染管线(marked + DOMPurify + highlight.js),并补齐了缺失的排版样式。
主要改动
新增共享渲染器
static/js/markdown.js(全局BlogMD):#锚点链接target="_blank" rel="noopener noreferrer"新增排版样式
static/css/markdown.css:.md-body作用域下的完整文章排版(标题层级、表格、列表、任务列表、引用块、行内/块级代码、图片、分割线等)。此前页面大量使用prose类,但项目用的是 Tailwind Play CDN,并未加载 typography 插件,导致文章/评论实际没有任何排版样式。修复的问题:
marked.setOptions({ mangle, headerIds })在parse之后调用且这两个选项在 marked v4+ 已被移除,属于无效代码 —— 已移除,改为marked.use()正确配置marked/marked.min.js实际解析到 v15.0.12,v16+ 已不再提供该 UMD 文件,不锁版本会随时失效)—— 统一固定 marked@15.0.12 / dompurify@3.4.13 / highlight.js@11.12.0编辑器:管理后台与作者的文章编辑器(EasyMDE)的预览 / 分屏预览接入
BlogMD,预览效果与发布后一致。其他:
main.go新增/static静态路由;install_linux.sh部署时同步安装static/目录。验证
go build ./.../go vet ./...通过<script>/iframe/onerror/javascript:均被剥离)