Extracting quote blocks using dataviewjs


What I’m trying to do

I’ve been searching high and low to find a way to extract all the quote blocks on a page into a javascript array. I cant find the object model for a page though so dont know if thats exposed

Things I have tried

if the property were “quoteblocks” code would look something like:

let quotesList = []
for (q of dv.page("Quotes").file.quoteblocks.values)
dv.paragraph(quotesList[Math.floor(Math.random() * quotesList.length)])


If by quote block you mean any line starting with one (or more) greater than sign, >, you need to read the entire file to get those blocks. Dataview don’t do that natively, before you start using plain javascript.

If you on the other hand format your quotes as either list items, or even better decorated tasks (aka custom checklists) dataview can list and choose random items a lot easier.

There might however be some plugin which already does have this functionality. Have you searched through the community plugins?

Thanks. I pinched the code I shared from something that worked with quotes as a list. I’ll need write myself some Python to transform to a list as I have a BIG file.

I ended up converting my quote file to a list as that was a simple search/repalce all. thanks for help

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