Skip to content

Build your personal knowledge base with Trilium Notes

using included note should create a relation, closes #820

zadam759e47bfcf32
diff --git a/src/entities/note.js b/src/entities/note.js
index 6eb87c5b25..da3a49cc51 100644
--- a/src/entities/note.js
+++ b/src/entities/note.js
@@ -805,7 +805,7 @@ class Note extends Entity {
WHERE noteId = ? AND
isDeleted = 0 AND
type = 'relation' AND
- name IN ('internalLink', 'imageLink', 'relationMapLink')`, [this.noteId]);
+ name IN ('internalLink', 'imageLink', 'relationMapLink', 'includeNoteLink')`, [this.noteId]);
}
/**
diff --git a/src/services/import/tar.js b/src/services/import/tar.js
index 49bedc41b0..8b0b58ce13 100644
--- a/src/services/import/tar.js
+++ b/src/services/import/tar.js
@@ -147,7 +147,7 @@ async function importTar(taskContext, fileBuffer, importRootNote) {
continue;
}
- if (attr.type === 'relation' && ['internalLink', 'imageLink', 'relationMapLink'].includes(attr.name)) {
+ if (attr.type === 'relation' && ['internalLink', 'imageLink', 'relationMapLink', 'includeNoteLink'].includes(attr.name)) {
// these relations are created automatically and as such don't need to be duplicated in the import
continue;
}
diff --git a/src/services/notes.js b/src/services/notes.js
index 79b7c193ca..dacf40d628 100644
--- a/src/services/notes.js
+++ b/src/services/notes.js
@@ -242,6 +242,20 @@ function findInternalLinks(content, foundLinks) {
return content.replace(/href="[^"]*#root/g, 'href="#root');
}
+function findIncludeNoteLinks(content, foundLinks) {
+ const re = /<section class="include-note" data-note-id="([a-zA-Z0-9]+)">/g;
+ let match;
+
+ while (match = re.exec(content)) {
+ foundLinks.push({
+ name: 'includeNoteLink',
+ value: match[1]
+ });
+ }
+
+ return content;
+}
+
function findRelationMapLinks(content, foundLinks) {
const obj = JSON.parse(content);
@@ -263,10 +277,11 @@ async function saveLinks(note, content) {
}
const foundLinks = [];
-
+console.log("Scanning", content);
if (note.type === 'text') {
content = findImageLinks(content, foundLinks);
content = findInternalLinks(content, foundLinks);
+ content = findIncludeNoteLinks(content, foundLinks);
}
else if (note.type === 'relation-map') {
findRelationMapLinks(content, foundLinks);