mirror of
https://github.com/laurent22/joplin.git
synced 2025-01-26 18:58:21 +02:00
Desktop: Fixes #4916: Fixed pasting of text and images from Word on Windows
This commit is contained in:
parent
a76b4a0d3e
commit
bb77d7171a
@ -12,6 +12,7 @@ const { clipboard } = require('electron');
|
|||||||
const mimeUtils = require('@joplin/lib/mime-utils.js').mime;
|
const mimeUtils = require('@joplin/lib/mime-utils.js').mime;
|
||||||
const md5 = require('md5');
|
const md5 = require('md5');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const uri2path = require('file-uri-to-path');
|
||||||
|
|
||||||
const logger = Logger.create('resourceHandling');
|
const logger = Logger.create('resourceHandling');
|
||||||
|
|
||||||
@ -142,21 +143,21 @@ export async function processPastedHtml(html: string) {
|
|||||||
if (!mappedResources[imageSrc]) {
|
if (!mappedResources[imageSrc]) {
|
||||||
try {
|
try {
|
||||||
if (imageSrc.startsWith('file')) {
|
if (imageSrc.startsWith('file')) {
|
||||||
const imageFilePath = path.normalize(unescape(imageSrc).substr(7));
|
const imageFilePath = path.normalize(uri2path(imageSrc));
|
||||||
const resourceDirPath = path.normalize(Setting.value('resourceDir'));
|
const resourceDirPath = path.normalize(Setting.value('resourceDir'));
|
||||||
|
|
||||||
if (imageFilePath.startsWith(resourceDirPath)) {
|
if (imageFilePath.startsWith(resourceDirPath)) {
|
||||||
mappedResources[imageSrc] = imageSrc;
|
mappedResources[imageSrc] = imageSrc;
|
||||||
} else {
|
} else {
|
||||||
const createdResource = await shim.createResourceFromPath(imageFilePath);
|
const createdResource = await shim.createResourceFromPath(imageFilePath);
|
||||||
mappedResources[imageSrc] = `file://${escape(Resource.fullPath(createdResource))}`;
|
mappedResources[imageSrc] = `file://${encodeURI(Resource.fullPath(createdResource))}`;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const filePath = `${Setting.value('tempDir')}/${md5(Date.now() + Math.random())}`;
|
const filePath = `${Setting.value('tempDir')}/${md5(Date.now() + Math.random())}`;
|
||||||
await shim.fetchBlob(imageSrc, { path: filePath });
|
await shim.fetchBlob(imageSrc, { path: filePath });
|
||||||
const createdResource = await shim.createResourceFromPath(filePath);
|
const createdResource = await shim.createResourceFromPath(filePath);
|
||||||
await shim.fsDriver().remove(filePath);
|
await shim.fsDriver().remove(filePath);
|
||||||
mappedResources[imageSrc] = `file://${escape(Resource.fullPath(createdResource))}`;
|
mappedResources[imageSrc] = `file://${encodeURI(Resource.fullPath(createdResource))}`;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.warn(`Error creating a resource for ${imageSrc}.`, error);
|
logger.warn(`Error creating a resource for ${imageSrc}.`, error);
|
||||||
|
35
packages/app-desktop/package-lock.json
generated
35
packages/app-desktop/package-lock.json
generated
@ -3199,7 +3199,8 @@
|
|||||||
},
|
},
|
||||||
"ini": {
|
"ini": {
|
||||||
"version": "1.3.5",
|
"version": "1.3.5",
|
||||||
"resolved": "",
|
"resolved": "https://registry.npmjs.org/ini/-/ini-1.3.5.tgz",
|
||||||
|
"integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true
|
"optional": true
|
||||||
},
|
},
|
||||||
@ -3260,7 +3261,8 @@
|
|||||||
},
|
},
|
||||||
"mkdirp": {
|
"mkdirp": {
|
||||||
"version": "0.5.1",
|
"version": "0.5.1",
|
||||||
"resolved": "",
|
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
|
||||||
|
"integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
@ -3425,7 +3427,8 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"minimist": {
|
"minimist": {
|
||||||
"version": "1.2.0",
|
"version": "1.2.0",
|
||||||
"resolved": "",
|
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
|
||||||
|
"integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true
|
"optional": true
|
||||||
}
|
}
|
||||||
@ -4218,6 +4221,15 @@
|
|||||||
"optional": true,
|
"optional": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"file-uri-to-path": "1.0.0"
|
"file-uri-to-path": "1.0.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"file-uri-to-path": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz",
|
||||||
|
"integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==",
|
||||||
|
"dev": true,
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"bl": {
|
"bl": {
|
||||||
@ -6964,11 +6976,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"file-uri-to-path": {
|
"file-uri-to-path": {
|
||||||
"version": "1.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-2.0.0.tgz",
|
||||||
"integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==",
|
"integrity": "sha512-hjPFI8oE/2iQPVe4gbrJ73Pp+Xfub2+WI2LlXDbsaJBwT5wuMh35WNWVYYTpnz895shtwfyutMFLFywpQAFdLg=="
|
||||||
"dev": true,
|
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"filelist": {
|
"filelist": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
@ -7649,7 +7659,8 @@
|
|||||||
},
|
},
|
||||||
"ini": {
|
"ini": {
|
||||||
"version": "1.3.5",
|
"version": "1.3.5",
|
||||||
"resolved": "",
|
"resolved": "https://registry.npmjs.org/ini/-/ini-1.3.5.tgz",
|
||||||
|
"integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true
|
"optional": true
|
||||||
},
|
},
|
||||||
@ -7893,7 +7904,8 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"minimist": {
|
"minimist": {
|
||||||
"version": "1.2.0",
|
"version": "1.2.0",
|
||||||
"resolved": "",
|
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
|
||||||
|
"integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true
|
"optional": true
|
||||||
}
|
}
|
||||||
@ -8354,7 +8366,8 @@
|
|||||||
},
|
},
|
||||||
"y18n": {
|
"y18n": {
|
||||||
"version": "3.2.1",
|
"version": "3.2.1",
|
||||||
"resolved": "",
|
"resolved": "https://registry.npmjs.org/y18n/-/y18n-3.2.1.tgz",
|
||||||
|
"integrity": "sha1-bRX7qITAhnnA136I53WegR4H+kE=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"yargs": {
|
"yargs": {
|
||||||
|
@ -133,6 +133,7 @@
|
|||||||
"electron-context-menu": "^0.15.0",
|
"electron-context-menu": "^0.15.0",
|
||||||
"electron-is-dev": "^0.3.0",
|
"electron-is-dev": "^0.3.0",
|
||||||
"electron-window-state": "^4.1.1",
|
"electron-window-state": "^4.1.1",
|
||||||
|
"file-uri-to-path": "^2.0.0",
|
||||||
"formatcoords": "^1.1.3",
|
"formatcoords": "^1.1.3",
|
||||||
"fs-extra": "^5.0.0",
|
"fs-extra": "^5.0.0",
|
||||||
"highlight.js": "^10.2.1",
|
"highlight.js": "^10.2.1",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user