mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Desktop: Fixes #4073: Resource links could not be opened from Rich Text editor on Linux
This commit is contained in:
parent
6463af0c31
commit
2b95bce272
@ -222,9 +222,11 @@ describe('models_Note', function() {
|
|||||||
const resourceDir = Setting.value('resourceDir');
|
const resourceDir = Setting.value('resourceDir');
|
||||||
const r1 = await shim.createResourceFromPath(`${__dirname}/../tests/support/photo.jpg`);
|
const r1 = await shim.createResourceFromPath(`${__dirname}/../tests/support/photo.jpg`);
|
||||||
const r2 = await shim.createResourceFromPath(`${__dirname}/../tests/support/photo.jpg`);
|
const r2 = await shim.createResourceFromPath(`${__dirname}/../tests/support/photo.jpg`);
|
||||||
|
const r3 = await shim.createResourceFromPath(`${__dirname}/../tests/support/welcome.pdf`);
|
||||||
const note1 = await Note.save({ title: 'note1' });
|
const note1 = await Note.save({ title: 'note1' });
|
||||||
const t1 = r1.updated_time;
|
const t1 = r1.updated_time;
|
||||||
const t2 = r2.updated_time;
|
const t2 = r2.updated_time;
|
||||||
|
const t3 = r3.updated_time;
|
||||||
|
|
||||||
const testCases = [
|
const testCases = [
|
||||||
[
|
[
|
||||||
@ -257,6 +259,11 @@ describe('models_Note', function() {
|
|||||||
`![](:/${r1.id}) ![](:/${r1.id}) ![](:/${r2.id})`,
|
`![](:/${r1.id}) ![](:/${r1.id}) ![](:/${r2.id})`,
|
||||||
`![](file://${resourceDir}/${r1.id}.jpg?t=${t1}) ![](file://${resourceDir}/${r1.id}.jpg?t=${t1}) ![](file://${resourceDir}/${r2.id}.jpg?t=${t2})`,
|
`![](file://${resourceDir}/${r1.id}.jpg?t=${t1}) ![](file://${resourceDir}/${r1.id}.jpg?t=${t1}) ![](file://${resourceDir}/${r2.id}.jpg?t=${t2})`,
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
true,
|
||||||
|
`![](:/${r3.id})`,
|
||||||
|
`![](file://${resourceDir}/${r3.id}.pdf)`,
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
for (const testCase of testCases) {
|
for (const testCase of testCases) {
|
||||||
|
@ -12,6 +12,7 @@ const ArrayUtils = require('../ArrayUtils.js');
|
|||||||
const lodash = require('lodash');
|
const lodash = require('lodash');
|
||||||
const urlUtils = require('../urlUtils.js');
|
const urlUtils = require('../urlUtils.js');
|
||||||
const markdownUtils = require('../markdownUtils').default;
|
const markdownUtils = require('../markdownUtils').default;
|
||||||
|
const { isImageMimeType } = require('../resourceUtils');
|
||||||
const { MarkupToHtml } = require('@joplin/renderer');
|
const { MarkupToHtml } = require('@joplin/renderer');
|
||||||
const { ALL_NOTES_FILTER_ID } = require('../reserved-ids');
|
const { ALL_NOTES_FILTER_ID } = require('../reserved-ids');
|
||||||
|
|
||||||
@ -149,7 +150,14 @@ class Note extends BaseItem {
|
|||||||
const id = resourceIds[i];
|
const id = resourceIds[i];
|
||||||
const resource = await Resource.load(id);
|
const resource = await Resource.load(id);
|
||||||
if (!resource) continue;
|
if (!resource) continue;
|
||||||
const resourcePath = options.useAbsolutePaths ? `${`file://${Resource.fullPath(resource)}` + '?t='}${resource.updated_time}` : Resource.relativePath(resource);
|
|
||||||
|
const isImage = isImageMimeType(resource.mime);
|
||||||
|
|
||||||
|
// We add a timestamp parameter for images, so that when they
|
||||||
|
// change, the preview is updated inside the note. This is not
|
||||||
|
// needed for other resources since they are simple links.
|
||||||
|
const timestampParam = isImage ? `?t=${resource.updated_time}` : '';
|
||||||
|
const resourcePath = options.useAbsolutePaths ? `file://${Resource.fullPath(resource)}${timestampParam}` : Resource.relativePath(resource);
|
||||||
body = body.replace(new RegExp(`:/${id}`, 'gi'), markdownUtils.escapeLinkUrl(resourcePath));
|
body = body.replace(new RegExp(`:/${id}`, 'gi'), markdownUtils.escapeLinkUrl(resourcePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user