chhoumann / quickadd

QuickAdd for Obsidian
https://quickadd.obsidian.guide
MIT License
1.5k stars 136 forks source link

Resolution of Templater syntax doesn't work in Captures as expected #568

Open voltel opened 1 year ago

voltel commented 1 year ago

The paradigm of capturing the "{{VALUE}}" and then manipulating the string with JavaScript inside the Templater brackets (between "<%" and "%>") doesn't work (see the example below).

> [!INFO]- Used abbreviations 
> - <% String.prototype.replace.call("{{VALUE:Abbreviations}}", /\r?\n/g, " ") %>

To Reproduce

  1. Create a Capture
  2. Insert the capture template similar to the one above or any of the variations, e.g.
    <% abbr = "{{VALUE:Abbreviations}}" %>
    <% "{{VALUE.Abbreviations}}".replace(/\r?\n/g, " ") %>
  3. Run the capture, see error: plugin:quickadd:17470 QuickAdd: (ERROR) Error: Template syntax error: Invalid or unexpected token

Expected behavior Similar to The Templater, when new files are created, the values in {{ }} are captured and then processed like string literals. E.g.:

<%*
c_abbr = "{{VALUE: Abbreviation}}".toUpperCase().trim();
c_abbr = (c_abbr == "~") ? "" : c_abbr; 
%>