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

Desktop: Fixes #6721: Fix exporting resources to md and md + frontmatter (#6768)

Co-authored-by: Henry Heino <46334387+personalizedrefrigerator@users.noreply.github.com>
Co-authored-by: Laurent Cozic <laurent22@users.noreply.github.com>
This commit is contained in:
SFulpius 2022-11-01 15:35:48 +01:00 committed by GitHub
parent 99a61f1283
commit 3dd008ae9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View File

@ -446,5 +446,23 @@ describe('interop/InteropService_Exporter_Md', function() {
const resourceFilename = (await fs.readdir(`${exportDir()}/_resources`))[0];
expect(fileExtension(resourceFilename)).toBe('jpg');
}));
it('should url encode resource links', (async () => {
const folder = await Folder.save({ title: 'testing' });
const note = await Note.save({ title: 'mynote', parent_id: folder.id });
await shim.attachFileToNote(note, `${supportDir}/photo.jpg`);
const resource: ResourceEntity = (await Resource.all())[0];
await Resource.save({ id: resource.id, title: 'name with spaces.jpg' });
const service = InteropService.instance();
await service.export({
path: exportDir(),
format: 'md',
});
const note_body = await shim.fsDriver().readFile(`${exportDir()}/testing/mynote.md`);
expect(note_body).toContain('[photo.jpg](../_resources/name%20with%20spaces.jpg)');
}));
});

View File

@ -72,7 +72,7 @@ export default class InteropService_Exporter_Md extends InteropService_Exporter_
for (let i = 0; i < linkedItemIds.length; i++) {
const id = linkedItemIds[i];
const itemPath = fn_createRelativePath(paths[id]);
newBody = newBody.replace(new RegExp(`:/${id}`, 'g'), itemPath);
newBody = newBody.replace(new RegExp(`:/${id}`, 'g'), markdownUtils.escapeLinkUrl(itemPath));
}
return newBody;