diff --git a/packages/app-cli/tests/models_Note.js b/packages/app-cli/tests/models_Note.js index 77a0b9286..5d8c9745a 100644 --- a/packages/app-cli/tests/models_Note.js +++ b/packages/app-cli/tests/models_Note.js @@ -222,9 +222,11 @@ describe('models_Note', function() { const resourceDir = Setting.value('resourceDir'); const r1 = 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 t1 = r1.updated_time; const t2 = r2.updated_time; + const t3 = r3.updated_time; const testCases = [ [ @@ -257,6 +259,11 @@ describe('models_Note', function() { `![](:/${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})`, ], + [ + true, + `![](:/${r3.id})`, + `![](file://${resourceDir}/${r3.id}.pdf)`, + ], ]; for (const testCase of testCases) { diff --git a/packages/lib/models/Note.js b/packages/lib/models/Note.js index 91c7ae661..1c687f40e 100644 --- a/packages/lib/models/Note.js +++ b/packages/lib/models/Note.js @@ -12,6 +12,7 @@ const ArrayUtils = require('../ArrayUtils.js'); const lodash = require('lodash'); const urlUtils = require('../urlUtils.js'); const markdownUtils = require('../markdownUtils').default; +const { isImageMimeType } = require('../resourceUtils'); const { MarkupToHtml } = require('@joplin/renderer'); const { ALL_NOTES_FILTER_ID } = require('../reserved-ids'); @@ -149,7 +150,14 @@ class Note extends BaseItem { const id = resourceIds[i]; const resource = await Resource.load(id); 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)); }