@@ -66,6 +66,11 @@ Script {
6666 property string tagMarker2
6767 property int maxTagLength
6868
69+ // Returns the preferred marker for writing new tags: primary if enabled, otherwise secondary
70+ function writeMarker () {
71+ return (useMarker1 && tagMarker) ? tagMarker : tagMarker2;
72+ }
73+
6974 // Returns an array of currently active tag markers
7075 function allMarkers () {
7176 var markers = [];
@@ -157,8 +162,8 @@ Script {
157162
158163 var noteText = note .noteText ;
159164 // Match a specific known tag with any active marker.
160- // Group 1 captures the leading space/newline so it is preserved on replace.
161- var tagRegExp = RegExp (" (^|\\ s)%1 %2(?=($|\\ s)) ?" .arg (pattern).arg (escapeRegExp (tagName).replace (/ / g , " _" )), " m" );
165+ // Group 1: leading space/newline, preserved on replace. Group 2: the matched marker .
166+ var tagRegExp = RegExp (" (^|\\ s)(%1) %2(?=($|\\ s)) ?" .arg (pattern).arg (escapeRegExp (tagName).replace (/ / g , " _" )), " m" );
162167
163168 switch (action) {
164169 // adds the tag "tagName" to the note
@@ -170,7 +175,7 @@ Script {
170175 return " " ;
171176 }
172177
173- var tag = tagMarker + tagName .replace (/ / g , " _" );
178+ var tag = writeMarker () + tagName .replace (/ / g , " _" );
174179
175180 // add the tag to the beginning or to the end of the note
176181 if (putToBeginning) {
@@ -217,7 +222,7 @@ Script {
217222 // the new note text has to be returned so that the note can be updated
218223 // returning an empty string indicates that nothing has to be changed
219224 case " rename" :
220- return noteText .replace (tagRegExp, " $1" + tagMarker + newTagName .replace (/ / g , " _" ));
225+ return noteText .replace (tagRegExp, " $1$2 " + newTagName .replace (/ / g , " _" ));
221226
222227 // returns a list of all tag names of the note
223228 case " list" :
0 commit comments