Templater : add new line in dynamic command output

What I’m trying to do

I want to parse the file content and match ‘important’ admonitions in order to automatically fill a summary table.

For example :

> [!important] [R1] Requirement 1
> something to achieve

> [!important] [R2] Requirement 2
> something to achieve

Should result in :

|R1|Requirement 1|
|R2|Requirement 2|

Things I have tried

I directly work inside my mardown file :

<%+* const regex = /> \\[!important]\s+\\[(.+)]\s+(.+)/g; let match; let ar = []; while((match = regex.exec(tp.file.content)) !== null) {ar.push('|'+match[1]+'|'+match[2]+'|'); }; tR += ar.join('\r\n'); %>

Which outputs:

|R1|Requirement 1|  |R2|Requirement 2|

This shows the closest result to what I expect, but I do not succeed in adding new lines between |R1|Requirement 1| and |R2|Requirement 2|.

I tried with '\\r\\n' and '<br>' instead of `‘\r\n’ without success. Moreover, ‘
’ visually break the line in preview mode such as the dynamic command is no more recognized :

Have you tried to only use \n?

You might also have an issue doing the <%+*… The support of that combination is somewhat sketchy, at least that is my experience. I wish for it to work, but you might be better off using dataviewjs.

It gives the same result as \r\n.

I’m trying to learn these things

I put in

> [!important] [R1] Requirement 1
> something to achieve

> [!important] [R2] Requirement 2
> something to achieve

I could not work with

<%+*
const regex = /> \\[!important]\s+\\[(.+)]\s+(.+)/g;
let match;
let ar = [];
while ((match = regex.exec(tp.file.content)) !== null) {
    ar.push('|' + match[1] + '|' + match[2] + '|');
}
tR += ar.join('\r\n');
%>

what it did was delete the text completely

After some digging, here some unofficial observations of mine:

  • It is interesting that one can define dynamic commands in the execution context, i.e., <%+*. This is not mentioned in the documentation.
  • My assumption is that dynamic commands only result in one line – maybe due to rendering? – and hence, the missing new line.

but the wrappers are not correct
throws error
had to delete out the plus
then without the plus if I run it with all text in doc selected, all text is deleted

and if the plus is included, how to wrap it correctly

doesn’t even achieve what OP managed to do

@stef.rausch In fact the templater doc is quiet poor. I found the <%+* command in the forum (Templater plugin (1.5 and newer): New Syntax and Examples - #20 by Moonbase59)

I also assume that the command should be in one line, from personal experiments and all exemples I could found.

@Yurcee : I found in gitlab issues that <%* has been deprecated, which seems right as no code inside <%* wrapper is working within my environment.

I succeed in creating a markdown table with external python code. I didn’t know about dataview and its capabilities in using regex. Thanks for pointing it to me @holroy. I may investigate this way.

@evera thanks for taking the time to answer

  • I tried the one-liner but still threw an error; used the same control text as you:

@Yurcee : I found in gitlab issues that <%* has been deprecated, which seems right as no code inside <%* wrapper is working within my environment.

I think you are mixing up things: as far as I know the dynamic command, i.e., <%+ is deprecated and not the execution command <%* – otherwise, a lot of templates would be robbed by their functionality.

Thanks for the pointer. I personally don’t use dynamic commands and rely more on the other two types. :wink:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.