Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions text2link/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "Text2link",
"identifier": "text2link",
"script": "text2link.qml",
"authors": [
"@Glin76"
],
"platforms": [
"linux",
"macos",
"windows"
],
"version": "0.0.1",
"minAppVersion": "25.05.3",
"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."
}
46 changes: 46 additions & 0 deletions text2link/text2link.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import QtQml 2.0

/**
* 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.
*/
QtObject {

function init() {
// create the menu entry
script.registerCustomAction("Text2link", "Create links for all notes containing selected text", "Text 2 link", "bookmark-new", true, false, true);
}

function customActionInvoked(identifier) {
switch (identifier) {
case "Text2link":

var text = script.noteTextEditSelectedText();
if (text == "") {break;}
var foundedNotes = -1; // Current note will not be counted
var addedLinks = 0;
var oldLinks = 0;
// loop for all notes containing the raw text
script.fetchNoteIdsByNoteTextPart(text).forEach(function (noteId) {
var note = script.fetchNoteById(noteId);
// first condition : text should be a complete word in the note
var reTest = RegExp("\\b"+text+"\\b","gi").exec(note.noteText);
// second condition : the note should not be already linked in this note
var link = "("+note.fileName+")";
while (link.search(" ") > -1) { // need to loop for each space because .replace() only works once
link = link.replace(" ","%20")
}
var alreadyLinked = script.currentNote().noteText.search(link)
// third condition : the note should not be self
if (reTest != null & alreadyLinked == -1 & script.currentNote().id != noteId) {
script.noteTextEditSetCursorPosition(-1); // end of the this note
script.noteTextEditWrite("\n\n"+"["+note.name+"]"+link); // add a blank line and the link
addedLinks += 1;
}
if (reTest != null) { foundedNotes += 1;}
if (alreadyLinked > 0) { oldLinks += 1;}
});
script.informationMessageBox(foundedNotes+" note(s) containing '"+text+"'\n"+oldLinks+" already linked\n"+addedLinks+" added", "Results");
break;
}
}
}