From 8f0052577cc87ca3f8ff77290627fe386ce32551 Mon Sep 17 00:00:00 2001 From: markyangkp Date: Thu, 28 May 2026 23:15:31 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20=E5=A4=8D=E5=88=B6/=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=20Markdown=20=E6=97=B6=E5=9B=BE=E7=89=87=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E4=B8=BA=E7=9B=B8=E5=AF=B9=E8=B7=AF=E5=BE=84=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E5=A4=96=E9=83=A8=E5=B7=A5=E5=85=B7=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 后端存储的 Markdown 图片使用根相对路径(/static/screenshots/...), 前端预览时临时补后端地址可以正常显示,但复制和下载直接使用了原始 相对路径,粘贴到外部 Markdown 工具后图片全部失效。 修复方案: - 新增 getBackendOrigin() 安全获取后端 origin,替代脆弱的 replace('/api', '') - 新增 toPortableMarkdown() 将根相对图片路径转为绝对 URL - Web 前端和扩展端所有复制/下载入口统一走转换函数 - 扩展端 absolutizeMarkdownImages 正则扩大为所有根相对路径,并排除 // 协议相对 URL --- .../src/components/MarkdownView.vue | 4 +-- BillNote_extension/src/logic/api.ts | 4 +-- .../src/sidepanel/Sidepanel.vue | 6 ++-- .../HomePage/components/MarkdownViewer.tsx | 10 +++--- BillNote_frontend/src/utils/index.ts | 31 +++++++++++++++++++ 5 files changed, 44 insertions(+), 11 deletions(-) diff --git a/BillNote_extension/src/components/MarkdownView.vue b/BillNote_extension/src/components/MarkdownView.vue index a492703f..ece27120 100644 --- a/BillNote_extension/src/components/MarkdownView.vue +++ b/BillNote_extension/src/components/MarkdownView.vue @@ -10,11 +10,11 @@ const md = new MarkdownIt({ html: false, linkify: true, breaks: true }) const html = computed(() => md.render(absolutizeMarkdownImages(stripSourceLink(props.markdown || '')))) async function copy() { - await navigator.clipboard.writeText(props.markdown) + await navigator.clipboard.writeText(absolutizeMarkdownImages(props.markdown)) } function download() { - const blob = new Blob([props.markdown], { type: 'text/markdown;charset=utf-8' }) + const blob = new Blob([absolutizeMarkdownImages(props.markdown)], { type: 'text/markdown;charset=utf-8' }) const url = URL.createObjectURL(blob) const a = document.createElement('a') a.href = url diff --git a/BillNote_extension/src/logic/api.ts b/BillNote_extension/src/logic/api.ts index 9f935ea2..6121380d 100644 --- a/BillNote_extension/src/logic/api.ts +++ b/BillNote_extension/src/logic/api.ts @@ -208,10 +208,10 @@ export async function ping(): Promise { } } -// markdown 里的 /static/screenshots/xxx 是相对路径,extension 渲染时需要拼绝对地址 +// markdown 里的根相对路径图片(如 /static/screenshots/xxx)需要拼绝对地址 export function absolutizeMarkdownImages(md: string): string { const base = backendUrl() - return md.replace(/!\[([^\]]*)\]\((\/static\/[^)]+)\)/g, (_, alt, path) => `![${alt}](${base}${path})`) + return md.replace(/!\[([^\]]*)\]\((?!https?:\/\/|data:|\/\/)(\/[^)]+)\)/g, (_, alt, path) => `![${alt}](${base}${path})`) } // backend 用 note_helper 在笔记开头插一行 '> 来源链接:URL'。侧边栏顶部已经有原片链接卡片, diff --git a/BillNote_extension/src/sidepanel/Sidepanel.vue b/BillNote_extension/src/sidepanel/Sidepanel.vue index 155625b7..f916e5c1 100644 --- a/BillNote_extension/src/sidepanel/Sidepanel.vue +++ b/BillNote_extension/src/sidepanel/Sidepanel.vue @@ -1,6 +1,6 @@