fix: 预览时本地图片不显示

问题: 重构后丢失了原始版本的图片路径转换逻辑,
      相对路径图片(如 ![](./images/logo.png))无法显示。

修复:
- 新增 rehypeFixImages 自定义 rehype 插件
- 在 sanitize 之后、highlight 之前执行
- 将相对路径 src 转换为 file:// 绝对路径
- 基于当前文件路径计算目录,拼接图片路径
- renderMarkdown 新增 filePath 可选参数
- Preview 组件传入 activeTab.filePath

示例:
  Markdown: ![](./images/logo.png)
  文件路径: /project/docs/README.md
  转换后:   file:///project/docs/images/logo.png
This commit is contained in:
thzxx
2026-05-27 21:13:31 +08:00
parent f9aaf19e19
commit d23d209522
2 changed files with 50 additions and 16 deletions
+1 -1
View File
@@ -19,7 +19,7 @@ export function Preview() {
}
const requestId = ++requestIdRef.current
renderMarkdown(activeTab.content).then(result => {
renderMarkdown(activeTab.content, activeTab.filePath).then(result => {
// M-07: 只有当 requestId 仍为最新时才更新
if (requestId === requestIdRef.current) {
setHtml(result)