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
auto linkification (plus some refactorings to silent pycharm warnings)
azivner1aeb0eec59f3
diff --git a/static/js/html2notecase.js b/static/js/html2notecase.jsindex b20775d37f..19f0a1e1b2 100644--- a/static/js/html2notecase.js+++ b/static/js/html2notecase.js@@ -12,13 +12,13 @@ function html2notecase(contents, note) {note.images = [];while (index < contents.length) {- if (contents[index] == '<') {- let found = false;+ let curContent = contents.substr(index);- let curContent = contents.substr(index);+ if (contents[index] === '<') {+ let found = false;let endOfTag = curContent.indexOf('>');- if (endOfTag == -1) {+ if (endOfTag === -1) {console.log("Can't find the end of the tag");}@@ -29,7 +29,7 @@ function html2notecase(contents, note) {for (tagId in tags) {let tag = tags[tagId];- if (contents.substr(index, tag.length) == tag) {+ if (contents.substr(index, tag.length) === tag) {found = true;// if (tagMap.get(index) == undefined) {// tagMap.get(index) = [];@@ -52,12 +52,12 @@ function html2notecase(contents, note) {}}- if (curTag.substr(0, 4) == "<img") {+ if (curTag.substr(0, 4) === "<img") {//console.log("Found img tag");let dataImagePos = curTag.indexOf('data:image/');- if (dataImagePos != -1) {+ if (dataImagePos !== -1) {let imageType = curTag.substr(dataImagePos + 11, 3);//console.log("image type: " + imageType);@@ -66,7 +66,7 @@ function html2notecase(contents, note) {let endOfDataPos = dataStart.indexOf('"');- if (endOfDataPos != -1) {+ if (endOfDataPos !== -1) {//console.log("Found the end of image data");let imageData = dataStart.substr(0, endOfDataPos);@@ -74,7 +74,7 @@ function html2notecase(contents, note) {note.images.push({note_id: note.detail.note_id,note_offset: index,- is_png: imageType == "png",+ is_png: imageType === "png",image_data: imageData});@@ -89,7 +89,7 @@ function html2notecase(contents, note) {let match = /^<a[^>]+?href="([^"]+?)"[^>]+?>([^<]+?)<\/a>/.exec(curContent);- if (match != null) {+ if (match !== null) {note.links.push({note_id: note.detail.note_id,note_offset: index,@@ -120,7 +120,22 @@ function html2notecase(contents, note) {}}else {- index++;+ let linkMatch = /^((https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/i.exec(curContent);++ if (linkMatch !== null) {+ note.links.push({+ note_id: note.detail.note_id,+ note_offset: index,+ target_url: linkMatch[1],+ lnk_text: linkMatch[1]+ });++ found = true;+ index += linkMatch[1].length;+ }+ else {+ index++;+ }}}diff --git a/static/js/note.js b/static/js/note.jsindex 3685af85a2..8202f18c39 100644--- a/static/js/note.js+++ b/static/js/note.js@@ -124,7 +124,7 @@ function createNote(node, parentKey, target) {newNoteCreated = true;- if (target == 'after') {+ if (target === 'after') {node.appendSibling(newNode).setActive(true);}else {diff --git a/static/js/tree.js b/static/js/tree.jsindex 5459a4d524..c42b2cb005 100644--- a/static/js/tree.js+++ b/static/js/tree.js@@ -50,7 +50,7 @@ $(function(){hotkeys: {keydown: {"insert": function(node) {- let parentKey = (node.getParent() == null || node.getParent().key == "root_1") ? "root" : node.getParent().key;+ let parentKey = (node.getParent() === null || node.getParent().key === "root_1") ? "root" : node.getParent().key;createNote(node, parentKey, 'after');},@@ -63,7 +63,7 @@ $(function(){url: baseUrl + 'notes/' + node.key,type: 'DELETE',success: function(result) {- if (node.getParent() != null && node.getParent().getChildren().length <= 1) {+ if (node.getParent() !== null && node.getParent().getChildren().length <= 1) {node.getParent().folder = false;node.getParent().renderTitle();}@@ -74,7 +74,7 @@ $(function(){}},"shift+up": function(node) {- if (node.getPrevSibling() != null) {+ if (node.getPrevSibling() !== null) {$.ajax({url: baseUrl + 'notes/' + node.key + '/moveBefore/' + node.getPrevSibling().key,type: 'PUT',@@ -86,7 +86,7 @@ $(function(){}},"shift+down": function(node) {- if (node.getNextSibling() != null) {+ if (node.getNextSibling() !== null) {$.ajax({url: baseUrl + 'notes/' + node.key + '/moveAfter/' + node.getNextSibling().key,type: 'PUT',@@ -98,13 +98,13 @@ $(function(){}},"shift+left": function(node) {- if (node.getParent() != null) {+ if (node.getParent() !== null) {$.ajax({url: baseUrl + 'notes/' + node.key + '/moveAfter/' + node.getParent().key,type: 'PUT',contentType: "application/json",success: function(result) {- if (node.getParent() != null && node.getParent().getChildren().length <= 1) {+ if (node.getParent() !== null && node.getParent().getChildren().length <= 1) {node.getParent().folder = false;node.getParent().renderTitle();}@@ -117,7 +117,7 @@ $(function(){"shift+right": function(node) {let prevSibling = node.getPrevSibling();- if (prevSibling != null) {+ if (prevSibling !== null) {$.ajax({url: baseUrl + 'notes/' + node.key + '/moveTo/' + prevSibling.key,type: 'PUT',diff --git a/static/js/utils.js b/static/js/utils.jsindex d9108d2be8..516902d0fa 100644--- a/static/js/utils.js+++ b/static/js/utils.js@@ -1,11 +1,15 @@function message(str) {- $("#top-message").fadeIn(1500);- $("#top-message").html(str);- $("#top-message").fadeOut(1500);+ const top = $("#top-message");++ top.fadeIn(1500);+ top.html(str);+ top.fadeOut(1500);}function error(str) {- $("#error-message").show();- $("#error-message").html(str);- $("#error-message").fadeOut(10000);+ const error = $("#error-message");++ error.show();+ error.html(str);+ error.fadeOut(10000);}\ No newline at end of file