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

Electron: Export/Import links to notes

This commit is contained in:
Laurent Cozic
2018-05-03 13:11:45 +01:00
parent 3aeb49b469
commit a6a351e68d
6 changed files with 121 additions and 33 deletions

View File

@ -107,7 +107,7 @@ class Note extends BaseItem {
return BaseModel.TYPE_NOTE;
}
static linkedResourceIds(body) {
static linkedItemIds(body) {
// For example: ![](:/fcca2938a96a22570e8eae2565bc6b0b)
if (!body || body.length <= 32) return [];
const matches = body.match(/\(:\/.{32}\)/g);
@ -115,6 +115,35 @@ class Note extends BaseItem {
return matches.map((m) => m.substr(3, 32));
}
static async linkedItems(body) {
const itemIds = this.linkedItemIds(body);
const output = [];
for (let i = 0; i < itemIds.length; i++) {
const item = await BaseItem.loadItemById(itemIds[i]);
if (!item) continue;
output.push(item);
}
return output;
}
static async linkedItemIdsByType(type, body) {
const items = await this.linkedItems(body);
const output = [];
for (let i = 0; i < items.length; i++) {
const item = items[i];
if (item.type_ === type) output.push(item.id);
}
return output;
}
static async linkedResourceIds(body) {
return await this.linkedItemIdsByType(BaseModel.TYPE_RESOURCE, body);
}
static new(parentId = '') {
let output = super.new();
output.parent_id = parentId;