Skip to content

Commit 87f7de6

Browse files
committed
lint: format code
Signed-off-by: Patrizio Bekerle <patrizio@bekerle.com>
1 parent db593d1 commit 87f7de6

File tree

2 files changed

+40
-42
lines changed

2 files changed

+40
-42
lines changed

text2link/info.json

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,8 @@
22
"name": "Text2link",
33
"identifier": "text2link",
44
"script": "text2link.qml",
5-
"authors": [
6-
"@Glin76"
7-
],
8-
"platforms": [
9-
"linux",
10-
"macos",
11-
"windows"
12-
],
5+
"authors": ["@Glin76"],
6+
"platforms": ["linux", "macos", "windows"],
137
"version": "0.0.1",
148
"minAppVersion": "25.05.3",
159
"description": "This script creates links to all notes containing the selected text at the end of the current note. Caution ! This script doesn't work with note-subfolders."

text2link/text2link.qml

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,47 @@ import QtQml 2.0
44
* This script creates links to all notes containing the selected text at the end of the current note. Caution ! This script doesn't work with note-subfolders.
55
*/
66
QtObject {
7-
8-
function init() {
9-
// create the menu entry
10-
script.registerCustomAction("Text2link", "Create links for all notes containing selected text", "Text 2 link", "bookmark-new", true, false, true);
11-
}
12-
137
function customActionInvoked(identifier) {
148
switch (identifier) {
15-
case "Text2link":
16-
17-
var text = script.noteTextEditSelectedText();
18-
if (text == "") {break;}
19-
var foundedNotes = -1; // Current note will not be counted
20-
var addedLinks = 0;
21-
var oldLinks = 0;
22-
// loop for all notes containing the raw text
23-
script.fetchNoteIdsByNoteTextPart(text).forEach(function (noteId) {
24-
var note = script.fetchNoteById(noteId);
25-
// first condition : text should be a complete word in the note
26-
var reTest = RegExp("\\b"+text+"\\b","gi").exec(note.noteText);
27-
// second condition : the note should not be already linked in this note
28-
var link = "("+note.fileName+")";
29-
while (link.search(" ") > -1) { // need to loop for each space because .replace() only works once
30-
link = link.replace(" ","%20")
31-
}
32-
var alreadyLinked = script.currentNote().noteText.search(link)
33-
// third condition : the note should not be self
34-
if (reTest != null & alreadyLinked == -1 & script.currentNote().id != noteId) {
35-
script.noteTextEditSetCursorPosition(-1); // end of the this note
36-
script.noteTextEditWrite("\n\n"+"["+note.name+"]"+link); // add a blank line and the link
37-
addedLinks += 1;
38-
}
39-
if (reTest != null) { foundedNotes += 1;}
40-
if (alreadyLinked > 0) { oldLinks += 1;}
41-
});
42-
script.informationMessageBox(foundedNotes+" note(s) containing '"+text+"'\n"+oldLinks+" already linked\n"+addedLinks+" added", "Results");
9+
case "Text2link":
10+
var text = script.noteTextEditSelectedText();
11+
if (text == "") {
4312
break;
13+
}
14+
var foundedNotes = -1; // Current note will not be counted
15+
var addedLinks = 0;
16+
var oldLinks = 0;
17+
// loop for all notes containing the raw text
18+
script.fetchNoteIdsByNoteTextPart(text).forEach(function (noteId) {
19+
var note = script.fetchNoteById(noteId);
20+
// first condition : text should be a complete word in the note
21+
var reTest = RegExp("\\b" + text + "\\b", "gi").exec(note.noteText);
22+
// second condition : the note should not be already linked in this note
23+
var link = "(" + note.fileName + ")";
24+
while (link.search(" ") > -1) {
25+
// need to loop for each space because .replace() only works once
26+
link = link.replace(" ", "%20");
27+
}
28+
var alreadyLinked = script.currentNote().noteText.search(link);
29+
// third condition : the note should not be self
30+
if (reTest != null & alreadyLinked == -1 & script.currentNote().id != noteId) {
31+
script.noteTextEditSetCursorPosition(-1); // end of the this note
32+
script.noteTextEditWrite("\n\n" + "[" + note.name + "]" + link); // add a blank line and the link
33+
addedLinks += 1;
34+
}
35+
if (reTest != null) {
36+
foundedNotes += 1;
37+
}
38+
if (alreadyLinked > 0) {
39+
oldLinks += 1;
40+
}
41+
});
42+
script.informationMessageBox(foundedNotes + " note(s) containing '" + text + "'\n" + oldLinks + " already linked\n" + addedLinks + " added", "Results");
43+
break;
4444
}
4545
}
46+
function init() {
47+
// create the menu entry
48+
script.registerCustomAction("Text2link", "Create links for all notes containing selected text", "Text 2 link", "bookmark-new", true, false, true);
49+
}
4650
}

0 commit comments

Comments
 (0)