fix: #775
This commit is contained in:
parent
160e339e1c
commit
d9c4db0c48
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -442,7 +442,7 @@ function md2remark(str: string) {
|
|||
.replace(
|
||||
/!\[(.*)\]\((.*)\)/g,
|
||||
(match, altText, 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);
|
||||
|
|
|
|||
|
|
@ -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("<img");
|
||||
|
|
@ -39,7 +39,7 @@ export async function syncMDBatch(saveDir: string, noteIds: number[]) {
|
|||
}
|
||||
for (const noteItem of noteItems) {
|
||||
const filename = await addon.api.sync.getMDFileName(noteItem.id, saveDir);
|
||||
const filePath = PathUtils.join(saveDir, filename);
|
||||
const filePath = jointPath(saveDir, filename);
|
||||
const content = await addon.api.convert.note2md(noteItem, saveDir, {
|
||||
keepNoteLink: false,
|
||||
withYAMLHeader: true,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import YAML = require("yamljs");
|
||||
import { getPref, setPref } from "../../utils/prefs";
|
||||
import { config } from "../../../package.json";
|
||||
import { fileExists, formatPath } from "../../utils/str";
|
||||
import { fileExists, formatPath, jointPath } from "../../utils/str";
|
||||
|
||||
export {
|
||||
initSyncList,
|
||||
|
|
@ -143,10 +143,10 @@ async function getMDStatus(
|
|||
filepath = source;
|
||||
} else if (typeof source === "number") {
|
||||
const syncStatus = getSyncStatus(source);
|
||||
filepath = PathUtils.join(syncStatus.path, syncStatus.filename);
|
||||
filepath = jointPath(syncStatus.path, syncStatus.filename);
|
||||
} else if (source.isNote && source.isNote()) {
|
||||
const syncStatus = getSyncStatus(source.id);
|
||||
filepath = PathUtils.join(syncStatus.path, syncStatus.filename);
|
||||
filepath = jointPath(syncStatus.path, syncStatus.filename);
|
||||
}
|
||||
filepath = formatPath(filepath);
|
||||
if (await fileExists(filepath)) {
|
||||
|
|
@ -173,7 +173,7 @@ async function getMDFileName(noteId: number, searchDir?: string) {
|
|||
if (
|
||||
(!searchDir || searchDir === syncStatus.path) &&
|
||||
syncStatus.filename &&
|
||||
(await fileExists(PathUtils.join(syncStatus.path, syncStatus.filename)))
|
||||
(await fileExists(jointPath(syncStatus.path, syncStatus.filename)))
|
||||
) {
|
||||
return syncStatus.filename;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { showHint } from "../../utils/hint";
|
||||
import { getString } from "../../utils/locale";
|
||||
import { getPref } from "../../utils/prefs";
|
||||
import { jointPath } from "../../utils/str";
|
||||
|
||||
export { setSyncing, callSyncing };
|
||||
|
||||
|
|
@ -150,7 +151,7 @@ async function callSyncing(
|
|||
progress: ((i - 1) / totalCount) * 100,
|
||||
});
|
||||
const item = Zotero.Items.get(syncStatus.itemID);
|
||||
const filepath = PathUtils.join(syncStatus.path, syncStatus.filename);
|
||||
const filepath = jointPath(syncStatus.path, syncStatus.filename);
|
||||
await addon.api.$import.fromMD(filepath, { noteId: item.id });
|
||||
// Update md file to keep the metadata synced
|
||||
await addon.api.$export.syncMDBatch(syncStatus.path, [item.id]);
|
||||
|
|
@ -166,7 +167,7 @@ async function callSyncing(
|
|||
|
||||
await addon.hooks.onShowSyncDiff(
|
||||
syncStatus.itemID,
|
||||
PathUtils.join(syncStatus.path, syncStatus.filename),
|
||||
jointPath(syncStatus.path, syncStatus.filename),
|
||||
);
|
||||
i += 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import seedrandom = require("seedrandom");
|
||||
import pathHelper = require("path-browserify");
|
||||
|
||||
export function slice(str: string, len: number) {
|
||||
return str.length > len ? `${str.slice(0, len - 3)}...` : str;
|
||||
|
|
@ -90,7 +91,7 @@ export async function fileExists(path: string): Promise<boolean> {
|
|||
|
||||
export function jointPath(...paths: string[]) {
|
||||
try {
|
||||
return formatPath(PathUtils.join(...paths));
|
||||
return formatPath(pathHelper.join(...paths));
|
||||
} catch (e) {
|
||||
ztoolkit.log("[jointPath]", e);
|
||||
return "";
|
||||
|
|
|
|||
Loading…
Reference in New Issue