Describe the bug
Using js quickadd in the Capture Fromat:
where val = “{{VALUE}}”, val.replace function assumes literal {{VALUE}}, not selection, if grep matches something in the literal string ”{{VALUE}}”, otherwise leaves selection.
If you simply return val, it returns the selection.
To Reproduce
let v = "{{VALUE}}";
return v.replace(/[VWXYZwxyz]/g, '9');
will incorrectly return {{9ALUE}} as the V matches in {{VALUE}}.
{{VALUE}} seemingly doesn’t get replaced with the selected text, but is taken literally.
Whereas, omitting the V in the grep pattern:
let v = "{{VALUE}}";
return v.replace(/[WXYZwxyz]/g, '9');
This will do nothing, and correctly return the selected text (not {{VALUE}}), because /[WXYZwxyz]/g doesn’t match anything in the string {{VALUE}}.
Expected behavior
replace should use the replacement selection string. In the example above, depending on the selection.
If selection = VWA, then replaced with 99A, not {{9ALUE}}
Desktop (please complete the following information):
- OS: macOS
- Obsidian: Version 1.5.12
- QuickAdd 1.6.1
Additional context
I’m trying to implement a “Convert Phone to Link” function:
function convertPhoneNumberToLink(linkNumber) {
// Remove all non-alphanumeric characters except +
linkNumber = linkNumber.replace(/[^a-zA-Z0-9+]/g, '');
// Replace letters with their corresponding numbers
linkNumber = linkNumber.replace(/[ABCabc]/g, '2');
linkNumber = linkNumber.replace(/[DEFdef]/g, '3');
linkNumber = linkNumber.replace(/[GHIghi]/g, '4');
linkNumber = linkNumber.replace(/[JKLjkl]/g, '5');
linkNumber = linkNumber.replace(/[MNOmno]/g, '6');
linkNumber = linkNumber.replace(/[PQRSpqrs]/g, '7');
linkNumber = linkNumber.replace(/[TUVtuv]/g, '8');
linkNumber = linkNumber.replace(/[WXYZwxyz]/g, '9');
return `tel:${linkNumber}`
}
return `[{{VALUE}}](${convertPhoneNumberToLink("{{VALUE}}")})`;
This will always return [ACTUAL PHONE NUMBER SELECTED](tel:82583) because 82582 is VALUE on the numeric keypad.
Describe the bug
Using
js quickaddin the Capture Fromat:where
val = “{{VALUE}}”,val.replacefunction assumes literal{{VALUE}}, not selection, if grep matches something in the literal string”{{VALUE}}”, otherwise leaves selection.If you simply
return val, it returns the selection.To Reproduce
will incorrectly return
{{9ALUE}}as theVmatches in{{VALUE}}.{{VALUE}}seemingly doesn’t get replaced with the selected text, but is taken literally.Whereas, omitting the
Vin the grep pattern:This will do nothing, and correctly return the selected text (not
{{VALUE}}), because/[WXYZwxyz]/gdoesn’t match anything in the string{{VALUE}}.Expected behavior
replace should use the replacement selection string. In the example above, depending on the selection.
If selection =
VWA, then replaced with99A, not{{9ALUE}}Desktop (please complete the following information):
Additional context
I’m trying to implement a “Convert Phone to Link” function:
This will always return
[ACTUAL PHONE NUMBER SELECTED](tel:82583)because 82582 is VALUE on the numeric keypad.