Skip to content

Commit a1cadd7

Browse files
starzepbek
andauthored
feat(in-note-text-tagging): add option to detect tags only at line start (#290)
* feat(in-note-text-tagging): add option to detect tags only at line start * build(in-note-text-tagging): add author and bump version * lint: format file Signed-off-by: Patrizio Bekerle <patrizio@bekerle.com> --------- Signed-off-by: Patrizio Bekerle <patrizio@bekerle.com> Co-authored-by: Patrizio Bekerle <patrizio@bekerle.com>
1 parent c3ac2de commit a1cadd7

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

‎in-note-text-tagging/in-note-text-tagging.qml‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,20 @@ Script {
5959
"type": "boolean",
6060
"default": "false"
6161
},
62+
{
63+
"identifier": "tagsAtLineStartOnly",
64+
"name": "Only detect tags at the beginning of a line",
65+
"description": "If enabled, only tags placed at the very start of a line are recognized (tags inline within text are ignored)",
66+
"type": "boolean",
67+
"default": "true"
68+
},
6269
]
6370
property bool useMarker1
6471
property string tagMarker
6572
property bool useMarker2
6673
property string tagMarker2
6774
property int maxTagLength
75+
property bool tagsAtLineStartOnly
6876

6977
// Returns the preferred marker for writing new tags: primary if enabled, otherwise secondary
7078
function writeMarker() {
@@ -168,8 +176,10 @@ Script {
168176

169177
var noteText = note.noteText;
170178
// Match a specific known tag with any active marker.
171-
// Group 1: leading space/newline, preserved on replace. Group 2: the matched marker.
172-
var tagRegExp = RegExp("(^|\\s)(%1)%2(?=($|\\s)) ?".arg(pattern).arg(escapeRegExp(tagName).replace(/ /g, "_")), "m");
179+
// When tagsAtLineStartOnly is enabled: only matches at the start of a line.
180+
// Otherwise: also matches tags preceded by whitespace (inline tags).
181+
// Group 1: leading anchor/whitespace, preserved on replace. Group 2: the matched marker.
182+
var tagRegExp = tagsAtLineStartOnly ? RegExp("(^)(%1)%2(?=($|\\s)) ?".arg(pattern).arg(escapeRegExp(tagName).replace(/ /g, "_")), "m") : RegExp("(^|\\s)(%1)%2(?=($|\\s)) ?".arg(pattern).arg(escapeRegExp(tagName).replace(/ /g, "_")), "m");
173183

174184
switch (action) {
175185
// adds the tag "tagName" to the note
@@ -237,7 +247,8 @@ Script {
237247
// a letter (including accented/Unicode) as first char.
238248
// Max length is controlled by tagBodyQuantifier().
239249
var excludedChars = allMarkers().map(escapeRegExp).join("");
240-
var re = new RegExp("(?:^|\\s)" + pattern + "([a-zA-Z" + "\\u00C0-\\u024F" + // Latin Extended A+B
250+
var linePrefix = tagsAtLineStartOnly ? "^" : "(?:^|\\s)";
251+
var re = new RegExp(linePrefix + pattern + "([a-zA-Z" + "\\u00C0-\\u024F" + // Latin Extended A+B
241252
"\\u0250-\\u02AF" + // IPA Extensions
242253
"\\u0370-\\u03FF" + // Greek and Coptic
243254
"\\u0400-\\u052F" + // Cyrillic + Supplement

‎in-note-text-tagging/info.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
"name": "@tag tagging in note text (experimental)",
33
"identifier": "in-note-text-tagging",
44
"script": "in-note-text-tagging.qml",
5-
"authors": ["@Maboroshy", "@luginf"],
5+
"authors": ["@Maboroshy", "@luginf", "@starze"],
66
"platforms": ["linux", "macos", "windows"],
7-
"version": "0.2.2",
7+
"version": "0.3.0",
88
"minAppVersion": "20.6.0",
99
"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\nIf you start writing a tag you can also use the autocompleter to get a list of already existing tags.\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."
1010
}

0 commit comments

Comments
 (0)