From c228f1bef6351c7298d190dc9d8f5b292e4d0d45 Mon Sep 17 00:00:00 2001 From: xiangyu <3170102889@zju.edu.cn> Date: Thu, 2 Jun 2022 00:51:31 +0800 Subject: [PATCH] fix: #29 export markdown bug on Mac --- src/Better Note Markdown.js | 12 ++++++++---- src/knowledge.ts | 10 ++++++++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Better Note Markdown.js b/src/Better Note Markdown.js index cb63707..12a6a44 100644 --- a/src/Better Note Markdown.js +++ b/src/Better Note Markdown.js @@ -1616,6 +1616,7 @@ let bundle; turndownService.use(turndownPluginGfm.gfm); async function convert(_Zotero, doc) { + Components.utils.import("resource://gre/modules/osfile.jsm"); // Transform `style="text-decoration: line-through"` nodes to (TinyMCE doesn't support ) doc.querySelectorAll("span").forEach(function (span) { if (span.style.textDecoration === "line-through") { @@ -1704,12 +1705,15 @@ let bundle; let ext = oldFile.split(".").pop(); let newFile = _Zotero.File.copyToUnique( oldFile, - `${_Zotero.Knowledge4Zotero.knowledge._exportPath}\\${imgKey}.${ext}` + OS.Path.join( + ...`${_Zotero.Knowledge4Zotero.knowledge._exportPath}/${imgKey}.${ext}`.split( + /\// + ) + ) ); Zotero.debug(newFile.path); - const newFilePath = `attachments\\${newFile.path - .split("\\") - .pop()}`; + let newPath = newFile.path.replace(/\\/g, "/"); + const newFilePath = `attachments/${newPath.split(/\//).pop()}`; img.setAttribute("src", newFilePath); img.setAttribute("alt", "image"); diff --git a/src/knowledge.ts b/src/knowledge.ts index 6a0b495..ae47a23 100644 --- a/src/knowledge.ts +++ b/src/knowledge.ts @@ -674,11 +674,17 @@ class Knowledge extends AddonBase { this._exportNote = newNote; this._exportPath = - Zotero.File.pathToFile(filename).parent.path + "\\attachments"; + Zotero.File.pathToFile(filename).parent.path + "/attachments"; + // Convert to unix format + this._exportPath = this._exportPath.replace(/\\/g, "/"); + + Components.utils.import("resource://gre/modules/osfile.jsm"); const hasImage = newNote.getNote().includes("