Dataview query to get all paragraphs that have ^example identifiers

I’d like to tag certain paragraphs of different notes, then have a dataview query (or some other method) to display them all.

For instance, if I have paragraphs of different notes all with the ^example block identifier, how do I create a query to see all paragraphs with that identifier? Ideally, I’d like them to be previewed as well (similar to the ![] syntax).

I appreciate any suggestions!

Following up on this. Any ideas?

Using the vanilla Search, you could put an embedded query in a note:

```query
^example
```

You can then cmd/ctrl + hover on the results to see the rendered note in the Page Preview pop-up, or use something like Query Control to render the note in the results list.

1 Like

You can try this:

```dataviewjs

// Query all pages
const allPages = dv.pages("");

// Crawl content and render table
const pages = await Promise.all(
    allPages.map(async (page) => {
        const content = await dv.io.load(page.file.path);
        const regexPattern = /(.*\^[1-9a-zA-ZÀ-ŰØ-űø-ÿ]{3,25}$)|(.*\n\^[1-9a-zA-ZÀ-ŰØ-űø-ÿ]{3,25}$)/gm;
        const regexMatches = content.match(regexPattern);

        if (regexMatches && regexMatches.length > 0) {
            return {
                link: page.file.link,
                content: regexMatches.join('\n')
            };
        }

        return null;
    })
);

const processedPages = pages.filter(p => p !== null);

dv.table(
    ["Note", "Content"],
    processedPages.map(p => [p.link, p.content])
);
```

Or you can do it by specifying your folder:

```dataviewjs

// Query folder
const allPages = dv.pages('"Put your folder name in here"');

// Crawl content and render table
const pages = await Promise.all(
    allPages.map(async (page) => {
        const content = await dv.io.load(page.file.path);
        const regexPattern = /(.*\^[1-9a-zA-ZÀ-ŰØ-űø-ÿ]{3,25}$)|(.*\n\^[1-9a-zA-ZÀ-ŰØ-űø-ÿ]{3,25}$)/gm;
        const regexMatches = content.match(regexPattern);

        if (regexMatches && regexMatches.length > 0) {
            return {
                link: page.file.link,
                content: regexMatches.join('\n')
            };
        }

        return null;
    })
);

const processedPages = pages.filter(p => p !== null);

dv.table(
    ["Note", "Content"],
    processedPages.map(p => [p.link, p.content])
);
```

Unfortunately, clicking on a note won’t take you to the position where the shown paragraph is. This is why I use inline queries for similar jobs.

1 Like

You’re being very generic in your request. Would you care explaining a little more in your use case? There are many ways to mark which can be tackled very differently.

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