Skip to content

Instantly share code, notes, and snippets.

@martonfekete
Created May 4, 2023 11:54
Show Gist options
  • Save martonfekete/7c7ceda239c12e6f58f3461c5018a540 to your computer and use it in GitHub Desktop.
Save martonfekete/7c7ceda239c12e6f58f3461c5018a540 to your computer and use it in GitHub Desktop.
Use Obsidian Dataview to collect all callouts from your files

Your table

// Get all pages
const pages = dv.pages()

// This regex will find the contents of the callout [!quote]
// If you want a different type to be found, update the "quote" to the corresponding callout format
const regex = /\s*\>\s*\[\!quote\]\n\s*>\s*(.*)\n/gm

const rows = []
for (const page of pages) {
  // Read the file contents
  const file = app.vault.getAbstractFileByPath(page.file.path)
  const contents = await app.vault.read(file);
  
  // Find quotes
  const quotes = contents.match(regex) || [];
  
  // Add all quotes to the rows
  if (quotes.length > 0) {
    rows.push([page.file.link, quotes.join('\n')])
  }
}

// Create table
dv.table(['Link', 'Quotes'], rows)
@notapelican
Copy link

This is exactly what I was looking for!

Is there a way to get rid of, or shrink the first column?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment