From d9c4db0c486bd0ee924f0a71bcf9262a38d579cb Mon Sep 17 00:00:00 2001 From: windingwind <33902321+windingwind@users.noreply.github.com> Date: Wed, 1 Nov 2023 11:49:15 +0800 Subject: [PATCH] fix: #775 --- package.json | 2 ++ src/modules/convert/api.ts | 6 +++--- src/modules/export/markdown.ts | 4 ++-- src/modules/sync/api.ts | 8 ++++---- src/modules/sync/hooks.ts | 5 +++-- src/utils/str.ts | 3 ++- 6 files changed, 16 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 00c3724..5b1788b 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,7 @@ "html-docx-js": "^0.3.1", "html-docx-js-typescript": "^0.1.5", "katex": "^0.16.8", + "path-browserify": "^1.0.1", "rehype-format": "^4.0.1", "rehype-parse": "^8.0.4", "rehype-remark": "^9.1.2", @@ -77,6 +78,7 @@ "@types/html-docx-js": "^0.3.1", "@types/katex": "^0.16.2", "@types/node": "^20.5.6", + "@types/path-browserify": "^1.0.1", "@types/seedrandom": "^3.0.5", "@types/yamljs": "^0.2.31", "@typescript-eslint/eslint-plugin": "^6.4.1", diff --git a/src/modules/convert/api.ts b/src/modules/convert/api.ts index c871bf0..da67d39 100644 --- a/src/modules/convert/api.ts +++ b/src/modules/convert/api.ts @@ -442,7 +442,7 @@ function md2remark(str: string) { .replace( /!\[(.*)\]\((.*)\)/g, (match, altText, imageURL) => - `![${altText}](${encodeURIComponent(imageURL)})`, + `![${altText}](${encodeURI(imageURL)})`, ); const remark = unified() .use(remarkGfm) @@ -812,7 +812,7 @@ function processN2MRehypeCitationNodes( visit( node, - (_n: any) => _n.properties?.className.includes("citation-item"), + (_n: any) => _n.properties?.className?.includes("citation-item"), (_n: any) => { return childNodes?.push(_n); }, @@ -1140,7 +1140,7 @@ async function processM2NRehypeImageNodes( : "file"; if (srcType === "file") { if (!PathUtils.isAbsolute(src)) { - src = PathUtils.joinRelative(fileDir, src); + src = jointPath(fileDir, src); } if (!(await fileExists(src))) { ztoolkit.log("parse image, path invalid", src); diff --git a/src/modules/export/markdown.ts b/src/modules/export/markdown.ts index bfd4aac..4ed103d 100644 --- a/src/modules/export/markdown.ts +++ b/src/modules/export/markdown.ts @@ -10,7 +10,7 @@ export async function saveMD( }, ) { const noteItem = Zotero.Items.get(noteId); - const dir = PathUtils.join( + const dir = jointPath( ...PathUtils.split(formatPath(filename)).slice(0, -1), ); const hasImage = noteItem.getNote().includes(" len ? `${str.slice(0, len - 3)}...` : str; @@ -90,7 +91,7 @@ export async function fileExists(path: string): Promise { export function jointPath(...paths: string[]) { try { - return formatPath(PathUtils.join(...paths)); + return formatPath(pathHelper.join(...paths)); } catch (e) { ztoolkit.log("[jointPath]", e); return "";