Creating Admonitions with DataView

Things I have tried

I searched the forums, discord, and google for any other instances of people creating admonitions or other codeblocks using DataView, and I couldn’t find anything on the subject. I also tried looking in DataView itself for alternatives to dv.paragraph() or .span() for outputting text, but didn’t find any.

What I’m trying to do

I’m trying to create a “current priorities” page that looks through my daily, weekly, monthly, quarterly, and annual notes for the field ‘priorities’ (a list of links) and create an admonition for each date note, with an admonition wrapping an embed of the priority file.

This is my current script (which is incomplete; I’m just trying to get any text content in the internal admonitions):

let DateSearch = [
	[ 'YYYY-MM-DD',  'today'        ],
	[ 'gggg-[W]ww',  'this week'    ],
	[ 'YYYY-MM MMM', 'this month'   ],
	[ 'YYYY-[Q]Q',   'this quarter' ],
	[ 'YYYY',        'this year'    ]
];

for (const date of DateSearch)
{
	let filename = moment().format(date[0])
	let file = dv.page(filename)

	let embed = 
		"````ad-note\n" +
		"collapse: open\n" +
		"title: [[" + filename + "|" + date[1] + "]]\n\n"
		+
		(file.priorities ?? []).map(priority =>
			"```ad-todo\n" +
			"title: " + priority + "\n" +
			"collapse: open" + "\n\n" +
			priority + "\n\n" + // this is the problem line
			"```"
		).join("\n\n")
		+ "\n\n" //edit: forgot to separate the end-code-blocks for the last nested admonition, but this didn't solve the problem
		+ "````\n\n"

	dv.span(embed)
}

That script with the line commented out produces the expected output:

But as soon as that commented line is included, I get this:

The same thing happens if I try to include any plain text that isn’t an attribute of the admonition. Notably, it’s not printing the link for each priority, but only the first priority from each pass through the loop and just ignoring the rest of the embed string for some reason.

It doesn’t have this behavior with markdown-formatted text in the admonition, if I replace the problem line with "- Sample\n\n" I get this:

1 Like

Have you tried looking at the HTML that is produced? Ctrl + Shift + I

The HTML result is just a span with the first priority link in it, nothing else.

I think the issue must be with DataView doing some sort of preprocessing on embed before creating the span.

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