From 276e4a0effce16b91e94d284292e7608115efeda Mon Sep 17 00:00:00 2001
From: quenousimporte <76260127+quenousimporte@users.noreply.github.com>
Date: Sun, 5 Feb 2023 10:04:07 +0100
Subject: [PATCH] added: experimental newtwork feature added: preview with
subnotes
---
index.html | 6 ++
main.js | 165 ++++++++++++++++++++++++++++++++++++++++++++---------
style.css | 8 +++
3 files changed, 151 insertions(+), 28 deletions(-)
diff --git a/index.html b/index.html
index f8977c7..92b5149 100644
--- a/index.html
+++ b/index.html
@@ -16,6 +16,12 @@
+
+
+
notes
diff --git a/main.js b/main.js
index 5c97c46..22abb05 100644
--- a/main.js
+++ b/main.js
@@ -13,7 +13,8 @@ var defaultsettings =
defaultpreviewinsplit: false,
enablefolding: false,
tagautocomplete: false,
- titleinaccentcolor: false
+ titleinaccentcolor: false,
+ enablenetwork: false
};
//builtin
@@ -186,6 +187,12 @@ var commands = [
action: togglepreview,
allowunsaved: true
},
+{
+ shortcut: "ctrl+shift+M",
+ hint: "Toggle preview with merged subnotes",
+ action: togglepreviewwithsubs,
+ allowunsaved: true
+},
{
shortcut: "ctrl+d",
hint: "Delete note",
@@ -638,8 +645,82 @@ function connected(note)
function shownotelinks()
{
- searchinlist(connected(currentnote).map(n => n.title))
- .then(loadnote);
+ if (settings.enablenetwork)
+ {
+ networkpage.hidden = false;
+ function id(note)
+ {
+ return localdata.indexOf(note);
+ }
+
+ var nodes = [];
+ var edges = [];
+
+ var list = [currentnote];
+
+ while (list.length)
+ {
+ var current = list.shift();
+ if (!nodes.find(n => n.id == id(current)))
+ {
+ nodes.push(
+ {
+ id: id(current),
+ label: current.title
+ });
+
+ var buddies = children(current).concat(parents(current));
+
+ list = list.concat(buddies);
+
+ buddies.
+ forEach(buddy => {
+ if (!edges.find(edge => (edge.to == id(current) && edge.from == id(buddy)) || (edge.to == id(buddy) && edge.from == id(current))))
+ {
+ edges.push({
+ from: id(current),
+ to: id(buddy)
+ });
+ }
+ });
+ }
+ }
+
+ var data = {
+ nodes: nodes,
+ edges: edges
+ };
+
+ var options =
+ {
+ nodes:
+ {
+ color:
+ {
+ background: settings.bgcolor,
+ border: settings.fontcolor,
+ },
+ font:
+ {
+ color: settings.fontcolor,
+ size: 16,
+ face: settings.fontfamily
+ }
+ }
+ };
+
+ var graph = new vis.Network(network, data, options);
+ graph.on("click", function(event)
+ {
+ loadnote(nodes.find(n => n.id == event.nodes[0]).label);
+ networkpage.hidden = true;
+ });
+ }
+ else
+ {
+ searchinlist(connected(currentnote).map(n => n.title))
+ .then(loadnote);
+ }
}
@@ -933,32 +1014,11 @@ function downloadvault()
function downloadnotewithsubs()
{
- try
+ var note = withsubs();
+ if (note)
{
- descendants(currentnote);
- }
- catch (err)
- {
- showtemporaryinfo("Loop detected");
- return;
- }
-
- var tempnote =
- {
- title: currentnote.title + " (with subnotes)",
- content: getnotecontent()
- };
-
- var kids = children(tempnote);
- while (kids.length)
- {
- kids.forEach(t =>
- {
- tempnote.content = tempnote.content.replaceAll("[[" + t + "]]", getnote(t).content);
- });
- kids = children(tempnote);
- }
- download(tempnote.title + ".md", tempnote.content);
+ download(note.title + ".md", note.content);
+ }
}
function downloadnote()
@@ -1807,6 +1867,7 @@ function showhelp()
help.push("## Libs");
help.push("[Showdown](https://showdownjs.com/)");
+ help.push("[vis-network](https://visjs.org/)");
help.push("## Fonts");
help.push("[Inconsolata](https://levien.com/type/myfonts/inconsolata.html)");
@@ -2154,6 +2215,54 @@ function togglepreview()
}
}
+function withsubs()
+{
+ try
+ {
+ descendants(currentnote);
+ }
+ catch (err)
+ {
+ showtemporaryinfo(err);
+ return null;
+ }
+
+ var tempnote =
+ {
+ title: currentnote.title + " (with subnotes)",
+ content: getnotecontent()
+ };
+
+ var kids = children(tempnote);
+ while (kids.length)
+ {
+ kids.forEach(kid =>
+ {
+ tempnote.content = tempnote.content.replaceAll("[[" + kid.title + "]]", kid.content);
+ });
+ kids = children(tempnote);
+ }
+
+ return tempnote;
+}
+
+function togglepreviewwithsubs()
+{
+ var note = withsubs();
+ if (note)
+ {
+ preview.innerHTML = md2html(note.content);
+ md.hidden = !md.hidden;
+ preview.hidden = !preview.hidden;
+
+ if (preview.hidden)
+ {
+ resize();
+ md.focus();
+ }
+ }
+}
+
function resetfolds()
{
folds = [];
diff --git a/style.css b/style.css
index 7b81733..bd636ab 100644
--- a/style.css
+++ b/style.css
@@ -53,6 +53,14 @@ body::-webkit-scrollbar-thumb {
background-color: inherit;
}
+#network {
+ position: absolute;
+ top: 0;
+ width: 100%;
+ height: 600px;
+ opacity: 1;
+}
+
/* top bar content */
#topbar {