Skip to content

Commit 4d83ade

Browse files
committed
lint: format code
Signed-off-by: Patrizio Bekerle <[email protected]>
1 parent 70bfbb6 commit 4d83ade

File tree

2 files changed

+48
-47
lines changed

2 files changed

+48
-47
lines changed

removedeadnotelink/info.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
{
2-
"name": "RemoveDeadNoteLink",
3-
"identifier": "removedeadnotelink",
4-
"script": "removedeadnotelink.qml",
5-
"authors": ["@Glin76"],
6-
"platforms": ["linux", "macos", "windows"],
7-
"version": "0.0.1",
8-
"minAppVersion": "25.6.1",
9-
"description": "This script creates a menu item and a button that searches through all notes and removes links to all notes (Markdown files) that no longer exist, also known as dead note links."
10-
}
1+
{
2+
"name": "RemoveDeadNoteLink",
3+
"identifier": "removedeadnotelink",
4+
"script": "removedeadnotelink.qml",
5+
"authors": ["@Glin76"],
6+
"platforms": ["linux", "macos", "windows"],
7+
"version": "0.0.1",
8+
"minAppVersion": "25.6.1",
9+
"description": "This script creates a menu item and a button that searches through all notes and removes links to all notes (Markdown files) that no longer exist, also known as dead note links."
10+
}

removedeadnotelink/removedeadnotelink.qml

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,51 +3,52 @@ import QtQml 2.0
33
/**
44
* This script creates a menu item and a button that search in all notes and remove links to note (MD file) no longer existing (aka dead note-link)
55
*/
6-
7-
QtObject {
86

7+
QtObject {
98
function customActionInvoked(identifier) {
109
switch (identifier) {
11-
case "RemoveDeadNoteLink":
12-
var dialogText = "";
13-
var reLink = RegExp("\\[.*\\]\\(.*\\.md\\)", "g"); // RegExp to find links : "[***](***.md)"
14-
script.fetchNoteIdsByNoteTextPart("").forEach(function (noteId){ // Loop for all notes
15-
var linkText = "";
16-
var note = script.fetchNoteById(noteId);
17-
var newNoteText = note.noteText;
18-
var LinkFound = reLink.exec(note.noteText);
19-
while (LinkFound != null){ // Loop for all links in the note
20-
var LinkNoteName = LinkFound.toString().replace(RegExp(".*\\(", "").exec(LinkFound),"") // RegExp to find the name of the link : from start of the link to "(", and then removed from the string
21-
LinkNoteName = LinkNoteName.toString().replace(RegExp(".*\\/", "").exec(LinkNoteName),"") // RegExp to find the relative path : from start to the last"/", and then removed from the string
22-
LinkNoteName = LinkNoteName.replace(")",""); // removing last ")" of the link
23-
while (LinkNoteName.search("%20") > -1) {
24-
LinkNoteName = LinkNoteName.replace("%20", " "); // replacing all the %20 by space in the filename
25-
}
26-
if (script.fetchNoteByFileName(LinkNoteName).id == 0) { // Does a note exist with that filename
27-
newNoteText = newNoteText.replace(LinkFound, ""); // removing the link in the future NoteText
28-
linkText += "\n - "+LinkFound;
29-
}
30-
LinkFound = reLink.exec(note.noteText);
10+
case "RemoveDeadNoteLink":
11+
var dialogText = "";
12+
var reLink = RegExp("\\[.*\\]\\(.*\\.md\\)", "g"); // RegExp to find links : "[***](***.md)"
13+
script.fetchNoteIdsByNoteTextPart("").forEach(function (noteId) {
14+
// Loop for all notes
15+
var linkText = "";
16+
var note = script.fetchNoteById(noteId);
17+
var newNoteText = note.noteText;
18+
var LinkFound = reLink.exec(note.noteText);
19+
while (LinkFound != null) {
20+
// Loop for all links in the note
21+
var LinkNoteName = LinkFound.toString().replace(RegExp(".*\\(", "").exec(LinkFound), ""); // RegExp to find the name of the link : from start of the link to "(", and then removed from the string
22+
LinkNoteName = LinkNoteName.toString().replace(RegExp(".*\\/", "").exec(LinkNoteName), ""); // RegExp to find the relative path : from start to the last"/", and then removed from the string
23+
LinkNoteName = LinkNoteName.replace(")", ""); // removing last ")" of the link
24+
while (LinkNoteName.search("%20") > -1) {
25+
LinkNoteName = LinkNoteName.replace("%20", " "); // replacing all the %20 by space in the filename
3126
}
32-
if (note.noteText != newNoteText) {
33-
script.setCurrentNote(note);
34-
script.noteTextEditSelectAll();
35-
script.noteTextEditWrite(newNoteText.trim());
36-
dialogText += "\n\nNote : "+note.name+" link(s) removed :"+linkText;
27+
if (script.fetchNoteByFileName(LinkNoteName).id == 0) {
28+
// Does a note exist with that filename
29+
newNoteText = newNoteText.replace(LinkFound, ""); // removing the link in the future NoteText
30+
linkText += "\n - " + LinkFound;
3731
}
38-
});
39-
40-
if (dialogText != "") {
41-
dialogText = "Here's the result of removing dead note-link(s)"+dialogText;
42-
script.informationMessageBox(dialogText);
43-
} else {
44-
script.informationMessageBox("No dead note-link found");
32+
LinkFound = reLink.exec(note.noteText);
4533
}
46-
break;
34+
if (note.noteText != newNoteText) {
35+
script.setCurrentNote(note);
36+
script.noteTextEditSelectAll();
37+
script.noteTextEditWrite(newNoteText.trim());
38+
dialogText += "\n\nNote : " + note.name + " link(s) removed :" + linkText;
39+
}
40+
});
41+
42+
if (dialogText != "") {
43+
dialogText = "Here's the result of removing dead note-link(s)" + dialogText;
44+
script.informationMessageBox(dialogText);
45+
} else {
46+
script.informationMessageBox("No dead note-link found");
47+
}
48+
break;
4749
}
4850
}
49-
5051
function init() {
51-
script.registerCustomAction("RemoveDeadNoteLink", "Remove dead links to note", "Remove dead note-link", "bookmark-new", true, false, true);
52+
script.registerCustomAction("RemoveDeadNoteLink", "Remove dead links to note", "Remove dead note-link", "bookmark-new", true, false, true);
5253
}
5354
}

0 commit comments

Comments
 (0)