mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
auto linkification (plus some refactorings to silent pycharm warnings)
This commit is contained in:
parent
5469b58cb7
commit
1aeb0eec59
@ -12,13 +12,13 @@ function html2notecase(contents, note) {
|
|||||||
note.images = [];
|
note.images = [];
|
||||||
|
|
||||||
while (index < contents.length) {
|
while (index < contents.length) {
|
||||||
if (contents[index] == '<') {
|
let curContent = contents.substr(index);
|
||||||
let found = false;
|
|
||||||
|
|
||||||
let curContent = contents.substr(index);
|
if (contents[index] === '<') {
|
||||||
|
let found = false;
|
||||||
let endOfTag = curContent.indexOf('>');
|
let endOfTag = curContent.indexOf('>');
|
||||||
|
|
||||||
if (endOfTag == -1) {
|
if (endOfTag === -1) {
|
||||||
console.log("Can't find the end of the tag");
|
console.log("Can't find the end of the tag");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ function html2notecase(contents, note) {
|
|||||||
for (tagId in tags) {
|
for (tagId in tags) {
|
||||||
let tag = tags[tagId];
|
let tag = tags[tagId];
|
||||||
|
|
||||||
if (contents.substr(index, tag.length) == tag) {
|
if (contents.substr(index, tag.length) === tag) {
|
||||||
found = true;
|
found = true;
|
||||||
// if (tagMap.get(index) == undefined) {
|
// if (tagMap.get(index) == undefined) {
|
||||||
// tagMap.get(index) = [];
|
// 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");
|
//console.log("Found img tag");
|
||||||
|
|
||||||
let dataImagePos = curTag.indexOf('data:image/');
|
let dataImagePos = curTag.indexOf('data:image/');
|
||||||
|
|
||||||
if (dataImagePos != -1) {
|
if (dataImagePos !== -1) {
|
||||||
let imageType = curTag.substr(dataImagePos + 11, 3);
|
let imageType = curTag.substr(dataImagePos + 11, 3);
|
||||||
|
|
||||||
//console.log("image type: " + imageType);
|
//console.log("image type: " + imageType);
|
||||||
@ -66,7 +66,7 @@ function html2notecase(contents, note) {
|
|||||||
|
|
||||||
let endOfDataPos = dataStart.indexOf('"');
|
let endOfDataPos = dataStart.indexOf('"');
|
||||||
|
|
||||||
if (endOfDataPos != -1) {
|
if (endOfDataPos !== -1) {
|
||||||
//console.log("Found the end of image data");
|
//console.log("Found the end of image data");
|
||||||
|
|
||||||
let imageData = dataStart.substr(0, endOfDataPos);
|
let imageData = dataStart.substr(0, endOfDataPos);
|
||||||
@ -74,7 +74,7 @@ function html2notecase(contents, note) {
|
|||||||
note.images.push({
|
note.images.push({
|
||||||
note_id: note.detail.note_id,
|
note_id: note.detail.note_id,
|
||||||
note_offset: index,
|
note_offset: index,
|
||||||
is_png: imageType == "png",
|
is_png: imageType === "png",
|
||||||
image_data: imageData
|
image_data: imageData
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ function html2notecase(contents, note) {
|
|||||||
|
|
||||||
let match = /^<a[^>]+?href="([^"]+?)"[^>]+?>([^<]+?)<\/a>/.exec(curContent);
|
let match = /^<a[^>]+?href="([^"]+?)"[^>]+?>([^<]+?)<\/a>/.exec(curContent);
|
||||||
|
|
||||||
if (match != null) {
|
if (match !== null) {
|
||||||
note.links.push({
|
note.links.push({
|
||||||
note_id: note.detail.note_id,
|
note_id: note.detail.note_id,
|
||||||
note_offset: index,
|
note_offset: index,
|
||||||
@ -120,7 +120,22 @@ function html2notecase(contents, note) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
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++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ function createNote(node, parentKey, target) {
|
|||||||
|
|
||||||
newNoteCreated = true;
|
newNoteCreated = true;
|
||||||
|
|
||||||
if (target == 'after') {
|
if (target === 'after') {
|
||||||
node.appendSibling(newNode).setActive(true);
|
node.appendSibling(newNode).setActive(true);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -50,7 +50,7 @@ $(function(){
|
|||||||
hotkeys: {
|
hotkeys: {
|
||||||
keydown: {
|
keydown: {
|
||||||
"insert": function(node) {
|
"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');
|
createNote(node, parentKey, 'after');
|
||||||
},
|
},
|
||||||
@ -63,7 +63,7 @@ $(function(){
|
|||||||
url: baseUrl + 'notes/' + node.key,
|
url: baseUrl + 'notes/' + node.key,
|
||||||
type: 'DELETE',
|
type: 'DELETE',
|
||||||
success: function(result) {
|
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().folder = false;
|
||||||
node.getParent().renderTitle();
|
node.getParent().renderTitle();
|
||||||
}
|
}
|
||||||
@ -74,7 +74,7 @@ $(function(){
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"shift+up": function(node) {
|
"shift+up": function(node) {
|
||||||
if (node.getPrevSibling() != null) {
|
if (node.getPrevSibling() !== null) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: baseUrl + 'notes/' + node.key + '/moveBefore/' + node.getPrevSibling().key,
|
url: baseUrl + 'notes/' + node.key + '/moveBefore/' + node.getPrevSibling().key,
|
||||||
type: 'PUT',
|
type: 'PUT',
|
||||||
@ -86,7 +86,7 @@ $(function(){
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"shift+down": function(node) {
|
"shift+down": function(node) {
|
||||||
if (node.getNextSibling() != null) {
|
if (node.getNextSibling() !== null) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: baseUrl + 'notes/' + node.key + '/moveAfter/' + node.getNextSibling().key,
|
url: baseUrl + 'notes/' + node.key + '/moveAfter/' + node.getNextSibling().key,
|
||||||
type: 'PUT',
|
type: 'PUT',
|
||||||
@ -98,13 +98,13 @@ $(function(){
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"shift+left": function(node) {
|
"shift+left": function(node) {
|
||||||
if (node.getParent() != null) {
|
if (node.getParent() !== null) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: baseUrl + 'notes/' + node.key + '/moveAfter/' + node.getParent().key,
|
url: baseUrl + 'notes/' + node.key + '/moveAfter/' + node.getParent().key,
|
||||||
type: 'PUT',
|
type: 'PUT',
|
||||||
contentType: "application/json",
|
contentType: "application/json",
|
||||||
success: function(result) {
|
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().folder = false;
|
||||||
node.getParent().renderTitle();
|
node.getParent().renderTitle();
|
||||||
}
|
}
|
||||||
@ -117,7 +117,7 @@ $(function(){
|
|||||||
"shift+right": function(node) {
|
"shift+right": function(node) {
|
||||||
let prevSibling = node.getPrevSibling();
|
let prevSibling = node.getPrevSibling();
|
||||||
|
|
||||||
if (prevSibling != null) {
|
if (prevSibling !== null) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: baseUrl + 'notes/' + node.key + '/moveTo/' + prevSibling.key,
|
url: baseUrl + 'notes/' + node.key + '/moveTo/' + prevSibling.key,
|
||||||
type: 'PUT',
|
type: 'PUT',
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
function message(str) {
|
function message(str) {
|
||||||
$("#top-message").fadeIn(1500);
|
const top = $("#top-message");
|
||||||
$("#top-message").html(str);
|
|
||||||
$("#top-message").fadeOut(1500);
|
top.fadeIn(1500);
|
||||||
|
top.html(str);
|
||||||
|
top.fadeOut(1500);
|
||||||
}
|
}
|
||||||
|
|
||||||
function error(str) {
|
function error(str) {
|
||||||
$("#error-message").show();
|
const error = $("#error-message");
|
||||||
$("#error-message").html(str);
|
|
||||||
$("#error-message").fadeOut(10000);
|
error.show();
|
||||||
|
error.html(str);
|
||||||
|
error.fadeOut(10000);
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user