Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
basic support for internal links
azivner5e8edf44691f
diff --git a/src/sql.py b/src/sql.pyindex 641f182b6a..14e85a019c 100644--- a/src/sql.py+++ b/src/sql.py@@ -17,6 +17,7 @@ def connect(documentPath):conn.row_factory = dict_factorydef insert(tablename, rec):+ # FIXME: SQL injection!keys = ','.join(rec.keys())question_marks = ','.join(list('?'*len(rec)))values = tuple(rec.values())diff --git a/static/js/html2notecase.js b/static/js/html2notecase.jsindex 0241175cd6..4843922e10 100644--- a/static/js/html2notecase.js+++ b/static/js/html2notecase.js@@ -31,18 +31,11 @@ function html2notecase(contents, note) {let curTag = curContent.substr(0, endOfTag + 1);- //console.log(contents);-for (tagId in tags) {let tag = tags[tagId];if (contents.substr(index, tag.length) === tag) {found = true;- // if (tagMap.get(index) == undefined) {- // tagMap.get(index) = [];- // }-- // tagMap.get(index).push(key);note.formatting.push({note_id: note.detail.note_id,@@ -97,31 +90,33 @@ function html2notecase(contents, note) {let match = /^<a[^>]+?href="([^"]+?)"[^>]+?>([^<]+?)<\/a>/.exec(curContent);if (match !== null) {- note.links.push({+ const targetUrl = match[1];+ const linkText = match[2];++ const newLink = {note_id: note.detail.note_id,note_offset: index,- target_url: match[1],- lnk_text: match[2]- });+ lnk_text: linkText+ };++ const noteIdMatch = /app#([A-Za-z0-9]{22})/.exec(targetUrl);++ if (noteIdMatch !== null) {+ newLink.target_note_id = noteIdMatch[1];+ }+ else {+ newLink.target_url = targetUrl;+ }++ note.links.push(newLink);//console.log("Found link with text: " + match[2] + ", targetting: " + match[1]);- contents = contents.substr(0, index) + match[2] + contents.substr(index + match[0].length);+ contents = contents.substr(0, index) + linkText + contents.substr(index + match[0].length);found = true;}- // let imageRegex = /<img[^>]+src="data:image\/(jpg|png);base64,([^>\"]+)"[^>]+>/;-- // console.log("Testing for image: " + curTag.substr(0, 100));- // console.log("End of image: " + curTag.substr(curTag.length - 100));-- // let match = imageRegex.exec(curTag);-- // if (match != null) {-- // }-if (!found) {contents = contents.substr(0, index) + contents.substr(index + endOfTag + 1);}@@ -130,17 +125,26 @@ function html2notecase(contents, note) {let linkMatch = /^(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]/i.exec(curContent);if (linkMatch !== null) {- note.links.push({+ let targetUrl = linkMatch[0];++ let newLink = {note_id: note.detail.note_id,note_offset: index,- target_url: linkMatch[0],- lnk_text: linkMatch[0]- });+ lnk_text: targetUrl+ };++ const noteIdMatch = /app#([A-Za-z0-9]{22})/.exec(targetUrl);++ if (noteIdMatch !== null) {+ newLink.target_note_id = noteIdMatch[1];+ }+ else {+ newLink.target_url = targetUrl;+ }- // console.log(linkMatch[0]);- // console.log(linkMatch[0].length);+ note.links.push(newLink);- index += linkMatch[0].length;+ index += targetUrl.length;}else {index++;diff --git a/static/js/note.js b/static/js/note.jsindex a83ae8cc1f..b3a642ef0c 100644--- a/static/js/note.js+++ b/static/js/note.js@@ -181,9 +181,9 @@ function addRecentNote(noteTreeId, noteContentId) {// we include the note into recent list only if the user stayed on the note at least 5 secondsif (noteTreeId === globalNote.detail.note_id || noteContentId === globalNote.detail.note_id) {// if it's already there, remove the note- recentNotes = recentNotes.filter(note => note !== noteTreeId);+ c = recentNotes.filter(note => note !== noteTreeId);- console.log("added after " + (new Date().getTime() - origDate.getTime()));+ //console.log("added after " + (new Date().getTime() - origDate.getTime()));recentNotes.unshift(noteTreeId);}diff --git a/static/js/notecase2html.js b/static/js/notecase2html.jsindex c4d66f9f76..fcd3c2020f 100644--- a/static/js/notecase2html.js+++ b/static/js/notecase2html.js@@ -26,7 +26,16 @@ function notecase2html(note) {}}else if (el.type === 'link') {- let linkHtml = '<a href="' + el.target_url + '">' + el.lnk_text + '</a>';+ let targetUrl;++ if (el.target_url) {+ targetUrl = el.target_url;+ }+ else {+ targetUrl = "app#" + el.target_note_id;+ }++ let linkHtml = '<a href="' + targetUrl + '">' + el.lnk_text + '</a>';noteText = noteText.substr(0, el.note_offset + offset) + noteText.substr(el.note_offset + offset + el.lnk_text.length);diff --git a/static/style.css b/static/style.cssindex bc545af950..9ac84598cd 100644--- a/static/style.css+++ b/static/style.css@@ -33,6 +33,7 @@ ul.fancytree-container {outline: none !important;}+/* icons from https://feathericons.com */span.fancytree-node > span.fancytree-icon {background-position: 0 0;background-image: url("icons/file.png");