While doing a multistep Quickadd macro one step is to capture some dataviewjs script into a specified note. Everything’s working so far except a tiny little thing - I don’t have a clue how to mask / escape the linebreak \n to transfer it properly into that note.
Things I have tried
I won’t paste all the sctipt but the part is not tranfered properly. In case it’s not enough I will paste the rest.
First Thing I tried
dv.paragraph('```tasks\n' + query + '\n```');
Transfered and shown Code:
dv.paragraph('```tasks
' + query + '
```');
As you can see the linebreaks aren’t transfered (but got done ^^) so the js won’t be able to create a valid code.
Second thing I tried
dv.paragraph('```tasks\\n' + query + '\\n```');
Transfered and shown Code:
dv.paragraph('```tasks
' + query + '
```');
As can be seen I tried to escape that \n with no success. I also tried \\\n - same result. Could anybody tell me how to mask / escape that nasty little thing properly or if there would be an alternative to have such linebreak (ah - tried <br> as well )?
One last remark - adding the \n manually after all that Quickadd stuff has been done works as wished.
As written I just didn’t paste all the code because it’s only that \n part not “being transfered” properly. This is not the first step it is the last one. The macro is to create a new project with a total of four notes. Two of those notes by creation get content by Quickadd captures. The last one is kind of a timeline showing all tasks (you’ll get it) in a timeline. Therefor I use Quickadd to capture some yaml and a dataviewjs into that Timeline-note. That dataviewjs checks in an if-loop if tasks with special project tags are existing. If yes that dv.paragraph part comes to life otherwise it just gives a message about no existing tasks. I will post all the capture below - just in case you are interested to see it.
It seems to capture js stuff into another note (that’s what I meant with “transfer” )you need to change \n into \u000a. You cannot use \n. That’s how I made it working finally.
Here is all the text captured into that timeline note.
String handling can be troublesome every now and then. One thing which might help out related to codeblocks is to use tildes instead of backticks.
And depending on context, what’s normally written as \n, might in some cases need to be escaped to become \\\n, in order for it to preserve its intended meaning. (I don’t remember why just now, but in one occasion we had to even double that up as well, so we had to write \\\\\\\n… That one was nasty)