fixed: loop detection in links

fixed: link and tag detection
removed: dot filter in note list
This commit is contained in:
quenousimporte 2023-01-30 09:18:23 +01:00
parent b703cec48a
commit 860f41a38e
1 changed files with 44 additions and 30 deletions

74
main.js
View File

@ -118,7 +118,7 @@ var themes =
bgcolor: "white", bgcolor: "white",
fontfamily: "'Josefin Sans', sans-serif", fontfamily: "'Josefin Sans', sans-serif",
fontsize: "16px", fontsize: "16px",
fontcolor: "rgb(54,54,54)", fontcolor: "rgb(78,78,78)",
lineheight: "24px", lineheight: "24px",
accentcolor: "rgb(54,54,54)" accentcolor: "rgb(54,54,54)"
} }
@ -410,12 +410,16 @@ function switchvault()
init(); init();
} }
function ascendants(note) function ancestors(note)
{ {
var list = parents(note); var list = parents(note);
list.forEach(title => list.forEach(title =>
{ {
list = list.concat(ascendants(localdata.find(n => n.title == title))); var parent = localdata.find(n => n.title == title);
if (parent && !list.find(p => p.title == parent))
{
list = list.concat(ancestors(parent));
}
}) })
return list; return list;
} }
@ -425,7 +429,11 @@ function descendants(note)
var list = children(note); var list = children(note);
list.forEach(title => list.forEach(title =>
{ {
list = list.concat(descendants(localdata.find(n => n.title == title))); var child = localdata.find(n => n.title == title);
if (child && !list.find(p => p.title == child))
{
list = list.concat(descendants(localdata.find(n => n.title == title)));
}
}) })
return list; return list;
} }
@ -446,15 +454,22 @@ function parents(note)
function showinternallinks() function showinternallinks()
{ {
var list = ascendants(currentnote).reverse(); try
var index = list.length; {
list.push(currentnote.title); var list = ancestors(currentnote).reverse();
list = list.concat(descendants(currentnote)); var index = list.length;
list.push(currentnote.title);
list = list.concat(descendants(currentnote));
//[...new Set(internal.concat(backlinks))] //[...new Set(internal.concat(backlinks))]
searchinlist(list, null, index) searchinlist(list, null, index)
.then(loadnote); .then(loadnote);
}
catch(err)
{
showtemporaryinfo("Loop, cannot show links");
}
} }
function showoutline() function showoutline()
@ -480,26 +495,28 @@ function showoutline()
}); });
} }
function getbetween(a, b)
{
var start = md.value.lastIndexOf(a, md.selectionStart);
if (start == -1 || md.value.substring(start, md.selectionStart).indexOf("\n") != -1) return "";
var end = md.value.indexOf(b, md.selectionStart);
if (end == -1 || md.value.substring(md.selectionStart, end).indexOf("\n") != -1) return "";
return md.value.substring(start + a.length, end);
}
function linkatpos() function linkatpos()
{ {
return getbetween("[[", "]]"); var start = md.value.lastIndexOf("[[", md.selectionStart);
if (start == -1 || md.value.substring(start, md.selectionStart).indexOf("\n") != -1) return "";
var end = md.value.indexOf("]]", md.selectionStart);
if (end == -1 || md.value.substring(md.selectionStart, end).indexOf("\n") != -1) return "";
return md.value.substring(start + 2, end);
} }
function tagatpos() function tagatpos()
{ {
// to improve: the last has no comma! var start = md.value.lastIndexOf(" ", md.selectionStart);
return getbetween(" ", ","); if (start == -1 || md.value.substring(start, md.selectionStart).indexOf("\n") != -1) return "";
var nextcomma = md.value.indexOf(",", md.selectionStart);
var nexteol = md.value.indexOf("\n", md.selectionStart);
var end = Math.min(nexteol, nextcomma);
if (end == -1 || md.value.substring(md.selectionStart, end).indexOf("\n") != -1) return "";
return md.value.substring(start + 1, end);
} }
function clickeditor() function clickeditor()
@ -601,7 +618,6 @@ function tagslist()
tags = {}; tags = {};
localdata localdata
.filter(n => !n.title.startsWith("."))
.forEach(n => .forEach(n =>
{ {
var ts = gettags(n); var ts = gettags(n);
@ -679,7 +695,6 @@ function download(filename, content)
function downloadnotes() function downloadnotes()
{ {
localdata localdata
.filter(note => !note.title.startsWith("."))
.forEach(note => .forEach(note =>
{ {
download(note.title + ".md", note.content); download(note.title + ".md", note.content);
@ -841,6 +856,7 @@ function init()
.then(data => .then(data =>
{ {
localdata = data; localdata = data;
window.localStorage.setItem("remote", JSON.stringify(data));
loadlast(); loadlast();
}) })
.catch(remotecallfailed); .catch(remotecallfailed);
@ -1161,8 +1177,7 @@ function list()
{ {
return localdata return localdata
.filter(n => currenttag == "" || gettags(n).includes(currenttag)) .filter(n => currenttag == "" || gettags(n).includes(currenttag))
.map(n => n.title) .map(n => n.title);
.filter(t => !t.startsWith("."));
} }
function loadlast() function loadlast()
@ -1180,7 +1195,6 @@ function grep(needle)
var result = {}; var result = {};
localdata localdata
.filter(n => !n.title.startsWith("."))
.forEach(note => .forEach(note =>
{ {
if (note.title.toLowerCase().includes(needle.toLowerCase())) if (note.title.toLowerCase().includes(needle.toLowerCase()))