From 7f326d1a87ba986ff6977afaba45064454ab6342 Mon Sep 17 00:00:00 2001 From: xiangyu <3170102889@zju.edu.cn> Date: Thu, 2 Jun 2022 11:31:35 +0800 Subject: [PATCH] fix: export bug on Mac --- src/Better Note Markdown.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/Better Note Markdown.js b/src/Better Note Markdown.js index 12a6a44..6d407b7 100644 --- a/src/Better Note Markdown.js +++ b/src/Better Note Markdown.js @@ -1703,19 +1703,26 @@ let bundle; let oldFile = String(await attachmentItem.getFilePathAsync()); Zotero.debug(oldFile); let ext = oldFile.split(".").pop(); - let newFile = _Zotero.File.copyToUnique( - oldFile, - OS.Path.join( - ...`${_Zotero.Knowledge4Zotero.knowledge._exportPath}/${imgKey}.${ext}`.split( - /\// - ) + let newAbsPath = OS.Path.join( + ...`${_Zotero.Knowledge4Zotero.knowledge._exportPath}/${imgKey}.${ext}`.split( + /\// ) ); - Zotero.debug(newFile.path); - let newPath = newFile.path.replace(/\\/g, "/"); - const newFilePath = `attachments/${newPath.split(/\//).pop()}`; + Zotero.debug(newAbsPath); + if (!Zotero.isWin && newAbsPath.charAt(0) !== "/") { + newAbsPath = "/" + newAbsPath; + } + let newFile = oldFile; + try { + newFile = _Zotero.File.copyToUnique(oldFile, newAbsPath).path; + newFile = newFile.replace(/\\/g, "/"); + newFile = `attachments/${newFile.split(/\//).pop()}`; + } catch (e) { + Zotero.debug(e); + } + Zotero.debug(newFile); - img.setAttribute("src", newFilePath); + img.setAttribute("src", newFile); img.setAttribute("alt", "image"); }