mirror of
https://github.com/marty-oehme/scripts.git
synced 2024-12-22 07:58:08 +00:00
added script in-note-text-tagging
This commit is contained in:
parent
017f3f0378
commit
2a09fac1fd
2 changed files with 92 additions and 0 deletions
82
in-note-text-tagging/in-note-text-tagging.qml
Normal file
82
in-note-text-tagging/in-note-text-tagging.qml
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
import QtQml 2.0
|
||||||
|
import QOwnNotesTypes 1.0
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This script handles tagging in a note for tags in the note text like:
|
||||||
|
* @tag1 @tag2 @tag3
|
||||||
|
*/
|
||||||
|
Script {
|
||||||
|
/**
|
||||||
|
* Handles note tagging for a note
|
||||||
|
*
|
||||||
|
* This function is called when tags are added to, removed from or renamed in
|
||||||
|
* a note or the tags of a note should be listed
|
||||||
|
*
|
||||||
|
* @param note
|
||||||
|
* @param action can be "add", "remove", "rename" or "list"
|
||||||
|
* @param tagName tag name to be added, removed or renamed
|
||||||
|
* @param newTagName tag name to be renamed to if action = "rename"
|
||||||
|
* @return string or string-list (if action = "list")
|
||||||
|
*/
|
||||||
|
function noteTaggingHook(note, action, tagName, newTagName) {
|
||||||
|
var noteText = note.noteText;
|
||||||
|
var tagRegExp = RegExp("\\B@" + escapeRegExp(tagName) + "\\b");
|
||||||
|
|
||||||
|
switch (action) {
|
||||||
|
// adds the tag "tagName" to the note
|
||||||
|
// the new note text has to be returned so that the note can be updated
|
||||||
|
// returning an empty string indicates that nothing has to be changed
|
||||||
|
case "add":
|
||||||
|
// check if tag already exists
|
||||||
|
if (noteText.search(tagRegExp) > 0) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
// add the tag at the end of the note
|
||||||
|
noteText += "\n@" + tagName;
|
||||||
|
return noteText;
|
||||||
|
break;
|
||||||
|
|
||||||
|
// removes the tag "tagName" from the note
|
||||||
|
// the new note text has to be returned so that the note can be updated
|
||||||
|
// returning an empty string indicates that nothing has to be changed
|
||||||
|
case "remove":
|
||||||
|
noteText = noteText.replace(tagRegExp, "");
|
||||||
|
return noteText;
|
||||||
|
break;
|
||||||
|
|
||||||
|
// renames the tag "tagName" in the note to "newTagName"
|
||||||
|
// the new note text has to be returned so that the note can be updated
|
||||||
|
// returning an empty string indicates that nothing has to be changed
|
||||||
|
case "rename":
|
||||||
|
noteText = noteText.replace(tagRegExp, "@" + newTagName);
|
||||||
|
return noteText;
|
||||||
|
break;
|
||||||
|
|
||||||
|
// returns a list of all tag names of the note
|
||||||
|
case "list":
|
||||||
|
var re = new RegExp("\\B@([^\\s,]+)", "gi"),
|
||||||
|
result, tagNameList = [];
|
||||||
|
|
||||||
|
while ((result = re.exec(noteText)) !== null) {
|
||||||
|
var tagName = result[1];
|
||||||
|
|
||||||
|
// add the tag if it wasn't in the list
|
||||||
|
if (tagNameList.indexOf(tagName) == -1) {
|
||||||
|
tagNameList.push(tagName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tagNameList;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Escapes a string for regular expressions
|
||||||
|
*/
|
||||||
|
function escapeRegExp(str) {
|
||||||
|
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
|
||||||
|
}
|
||||||
|
}
|
10
in-note-text-tagging/info.json
Normal file
10
in-note-text-tagging/info.json
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"name": "@tag tagging in note text (experimental)",
|
||||||
|
"identifier": "in-note-text-tagging",
|
||||||
|
"script": "in-note-text-tagging.qml",
|
||||||
|
"authors": ["@pbek"],
|
||||||
|
"platforms": ["linux", "macos", "windows"],
|
||||||
|
"version": "0.0.1",
|
||||||
|
"minAppVersion": "17.09.9",
|
||||||
|
"description" : "With this script you can <b>store your tags in your note-text</b>. Use tags like <i>@tag</i> inside your note-text to tag your notes.\n\nYou also are able to use the functionality of the QOwnNotes user-interface to tag with this tags inside your note texts, like for adding a tag to the current note as well as bulk operations for adding and removing tags to your note. If you rename a tag inside QOwnNotes the text-tags in your notes are also updated.\n\nYou can also use this script as template for implementing your own, unique tagging mechanism.\n\n<b>If you install this script you will loose all current links between notes and tags and instead your in-note tags will be used!\n\nThis functionality is still experimental!</b> Please report your experiences."
|
||||||
|
}
|
Loading…
Reference in a new issue