1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Desktop: Fixes #1425 (probably): Fix display of images when using VSCode as external editor

This commit is contained in:
Laurent Cozic 2019-04-20 21:12:19 +01:00
parent 4ef05272c4
commit 220f5d0967
2 changed files with 9 additions and 4 deletions

View File

@ -6,7 +6,7 @@ const Resource = require('lib/models/Resource.js');
const Setting = require('lib/models/Setting.js');
const { shim } = require('lib/shim.js');
const { pregQuote } = require('lib/string-utils.js');
const { toSystemSlashes } = require('lib/path-utils.js');
const { toSystemSlashes, toFileProtocolPath } = require('lib/path-utils.js');
const { time } = require('lib/time-utils.js');
const { _ } = require('lib/locale.js');
const ArrayUtils = require('lib/ArrayUtils.js');
@ -177,14 +177,14 @@ class Note extends BaseItem {
const id = resourceIds[i];
const resource = await Resource.load(id);
if (!resource) continue;
body = body.replace(new RegExp(':/' + id, 'gi'), toSystemSlashes(Resource.fullPath(resource)));
body = body.replace(new RegExp(':/' + id, 'gi'), toFileProtocolPath(Resource.fullPath(resource)));
}
return body;
}
static async replaceResourceExternalToInternalLinks(body) {
const reString = pregQuote(toSystemSlashes(Resource.baseDirectoryPath() + '/')) + '[a-zA-Z0-9\.]+';
const reString = pregQuote(toFileProtocolPath(Resource.baseDirectoryPath() + '/')) + '[a-zA-Z0-9\.]+';
const re = new RegExp(reString, 'gi');
body = body.replace(re, (match) => {
const id = Resource.pathToId(match);

View File

@ -100,6 +100,11 @@ function friendlySafeFilename(e, maxLength = null) {
return output.substr(0, maxLength);
}
function toFileProtocolPath(path) {
const output = path.replace(/\\/g, "/");
return 'file://' + escape(output);
}
function toSystemSlashes(path, os = null) {
if (os === null) os = process.platform;
if (os === 'win32') return path.replace(/\//g, "\\");
@ -153,4 +158,4 @@ function extractExecutablePath(cmd) {
return output;
}
module.exports = { extractExecutablePath, basename, dirname, filename, isHidden, fileExtension, safeFilename, friendlySafeFilename, safeFileExtension, toSystemSlashes, rtrimSlashes, ltrimSlashes, quotePath, unquotePath };
module.exports = { toFileProtocolPath, extractExecutablePath, basename, dirname, filename, isHidden, fileExtension, safeFilename, friendlySafeFilename, safeFileExtension, toSystemSlashes, rtrimSlashes, ltrimSlashes, quotePath, unquotePath };