mirror of
https://github.com/marty-oehme/scripts.git
synced 2024-12-22 07:58:08 +00:00
Merge pull request #11 from Maboroshy/master
Added tag marker setting and multi-word tags
This commit is contained in:
commit
df602298c6
2 changed files with 20 additions and 7 deletions
|
@ -4,8 +4,21 @@ import QOwnNotesTypes 1.0
|
||||||
/**
|
/**
|
||||||
* This script handles tagging in a note for tags in the note text like:
|
* This script handles tagging in a note for tags in the note text like:
|
||||||
* @tag1 @tag2 @tag3
|
* @tag1 @tag2 @tag3
|
||||||
|
* @tag_one would tag the note with "tag one" tag.
|
||||||
*/
|
*/
|
||||||
Script {
|
Script {
|
||||||
|
property string tagMarker
|
||||||
|
|
||||||
|
property variant settingsVariables: [
|
||||||
|
{
|
||||||
|
"identifier": "tagMarker",
|
||||||
|
"name": "Tag word marker",
|
||||||
|
"description": "A word that starts with this characters is recognized as tag",
|
||||||
|
"type": "string",
|
||||||
|
"default": "@",
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles note tagging for a note
|
* Handles note tagging for a note
|
||||||
*
|
*
|
||||||
|
@ -20,7 +33,7 @@ Script {
|
||||||
*/
|
*/
|
||||||
function noteTaggingHook(note, action, tagName, newTagName) {
|
function noteTaggingHook(note, action, tagName, newTagName) {
|
||||||
var noteText = note.noteText;
|
var noteText = note.noteText;
|
||||||
var tagRegExp = RegExp("\\B@" + escapeRegExp(tagName) + "\\b");
|
var tagRegExp = RegExp("\\B%1($|\\s|\\b)".arg(escapeRegExp(tagMarker + tagName).replace(" ", "_")));
|
||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
// adds the tag "tagName" to the note
|
// adds the tag "tagName" to the note
|
||||||
|
@ -33,7 +46,7 @@ Script {
|
||||||
}
|
}
|
||||||
|
|
||||||
// add the tag at the end of the note
|
// add the tag at the end of the note
|
||||||
noteText += "\n@" + tagName;
|
noteText += "\n" + tagMarker + tagName.replace(" ", "_");
|
||||||
return noteText;
|
return noteText;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -49,17 +62,17 @@ Script {
|
||||||
// the new note text has to be returned so that the note can be updated
|
// 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
|
// returning an empty string indicates that nothing has to be changed
|
||||||
case "rename":
|
case "rename":
|
||||||
noteText = noteText.replace(tagRegExp, "@" + newTagName);
|
noteText.replace(tagRegExp, tagMarker + newTagName.replace(" ", "_"));
|
||||||
return noteText;
|
return noteText;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// returns a list of all tag names of the note
|
// returns a list of all tag names of the note
|
||||||
case "list":
|
case "list":
|
||||||
var re = new RegExp("\\B@([^\\s,]+)", "gi"),
|
var re = new RegExp("\\B%1([^\\s,;]+)".arg(escapeRegExp(tagMarker)), "gi"),
|
||||||
result, tagNameList = [];
|
result, tagNameList = [];
|
||||||
|
|
||||||
while ((result = re.exec(noteText)) !== null) {
|
while ((result = re.exec(noteText)) !== null) {
|
||||||
var tagName = result[1];
|
var tagName = result[1].replace("_", " ");
|
||||||
|
|
||||||
// add the tag if it wasn't in the list
|
// add the tag if it wasn't in the list
|
||||||
if (tagNameList.indexOf(tagName) == -1) {
|
if (tagNameList.indexOf(tagName) == -1) {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
"script": "in-note-text-tagging.qml",
|
"script": "in-note-text-tagging.qml",
|
||||||
"authors": ["@pbek"],
|
"authors": ["@pbek"],
|
||||||
"platforms": ["linux", "macos", "windows"],
|
"platforms": ["linux", "macos", "windows"],
|
||||||
"version": "0.0.1",
|
"version": "0.0.2",
|
||||||
"minAppVersion": "17.09.9",
|
"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 links between notes and tags and instead your in-note tags will be used!\n\nThis functionality is still experimental!</b>\nPlease report your experiences."
|
"description" : "With this script you can <b>store your tags in your note-text</b>. Use tags like <i>@tag</i> or <i>@tag_one</i> for 'tag one' inside your note-text to tag your notes. You can change '@' to something else in script settings.\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 links between notes and tags and instead your in-note tags will be used!\n\nThis functionality is still experimental!</b>\nPlease report your experiences."
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue