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

Desktop: Fixes #7782: Markdown + Front Matter export fails when tag(s) lost (#7820)

This commit is contained in:
pedr 2023-02-21 14:57:04 -03:00 committed by GitHub
parent 9e73d3590b
commit 6a9848ebe7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View File

@ -131,4 +131,15 @@ describe('interop/InteropService_Exporter_Md_frontmatter', () => {
expect(content).not.toContain('longitude');
expect(content).not.toContain('altitude');
}));
test('should export note without tag keyword if the tag has been deleted', (async () => {
const folder1 = await Folder.save({ title: 'folder1' });
const note = await Note.save({ title: 'NoTag', body: '**ma note**', parent_id: folder1.id });
const tag = await Tag.save({ title: 'tag' });
await Tag.setNoteTagsByIds(note.id, [tag.id]);
await Tag.delete(tag.id);
const content = await exportAndLoad(`${exportDir()}/folder1/NoTag.md`);
expect(content).not.toContain('tag');
}));
});

View File

@ -127,8 +127,12 @@ export default class InteropService_Exporter_Md_frontmatter extends InteropServi
const context: FrontMatterContext = this.context();
if (context.noteTags[note.id]) {
const tagIds = context.noteTags[note.id];
const tags = tagIds.map((id: string) => context.tagTitles[id]).sort();
md['tags'] = tags;
// In some cases a NoteTag can still exist, while the Tag does not. In this case, tagTitles
// for that tagId will return undefined, which can't be handled by the yaml library (issue #7782)
const tags = tagIds.map((id: string) => context.tagTitles[id]).filter(e => !!e).sort();
if (tags.length > 0) {
md['tags'] = tags;
}
}
// This guarentees that fields will always be ordered the same way