1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-06-15 23:00:36 +02:00

Desktop: Create fileURLs via drag and drop (#1653)

* enable drag and drop fileURLs

* fix windows fileURL syntax

* introduce encodeURI function

* fixed encoding issue

* use path-utils.js to deal with fileURL path conversion

* add changes as requested

* Minor rewording 'On the' -> 'In the', additional info about attaching files

* change call of toFileProtocolPath

* enable test script to check syntax for all OS-platforms
This commit is contained in:
tfinnberg
2019-07-29 12:16:47 +02:00
committed by Laurent Cozic
parent 38a51070fc
commit f7fcabbf41
5 changed files with 75 additions and 23 deletions

View File

@ -101,9 +101,18 @@ function friendlySafeFilename(e, maxLength = null) {
return output.substr(0, maxLength);
}
function toFileProtocolPath(path) {
const output = path.replace(/\\/g, "/");
return 'file://' + escape(output);
function toFileProtocolPath(filePathEncode, os = null) {
if (os === null) os = process.platform;
if (os === 'win32') {
filePathEncode = filePathEncode.replace(/\\/g, '/'); // replace backslash in windows pathname with slash e.g. c:\temp to c:/temp
filePathEncode = "/" + filePathEncode; // put slash in front of path to comply with windows fileURL syntax
}
filePathEncode = encodeURI(filePathEncode);
filePathEncode = filePathEncode.replace(/\+/g, '%2B'); // escape '+' with unicode
filePathEncode = filePathEncode.replace(/%20/g, '+'); // switch space (%20) with '+'. To comply with syntax used by joplin, see urldecode_(str) in MdToHtml.js
return "file://" + filePathEncode.replace(/\'/g, '%27'); // escape '(single quote) with unicode, to prevent crashing the html view
}
function toSystemSlashes(path, os = null) {