Quickadd :: transfer dataviewjs (linebreak) to note

What I’m trying to do

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 :wink: )?

One last remark - adding the \n manually after all that Quickadd stuff has been done works as wished.

What do you mean with transferred code? This seems like a pure call to dv.paragraph(), and not a text to be transferred?

And what element is it that the call to dataview is supposed to change (or output to) , if this is the first step in a QuickAdd macro?

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” :wink: )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.

---
cssclass: note_lin
banner: "![[project.jpg]]"
banner_y: 0.6
type: project
tags: 
alias:
project: 
PID: {{VALUE:PID 23-P#}}
status: 
projectTasks: 0
tasksCompleted: 0
---

<div class="title" style="color:White;">PROJECT :: {{VALUE: Projektname}}</div>

```dataviewjs
const result = await dv.query(`
LIST WITHOUT ID PID
FROM "040 XXXX/XXXXXXXX/{{VALUE: Projektname}}/{{VALUE: Projektname}}-Timeline"
SORT priority asc
`)

if (result.successful) {
	if (result.value.values.length > 0) {
	    const query = `
	        (tags includes ${result.value.values})
	        sort by happens asc
	    `;

	    dv.paragraph('```tasks\u000a' + query + '\u000a```');
	} else {
	    const message = `No tasks found! Create some!`
	    dv.paragraph(message)
	}
} else {
	dv.paragraph("~~~~ " + result.error + " ~~~~")
}

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)

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