Query to return whole paragraph where tag is inline

Is there a way to use a query/dataview/dataviewjs and return an entire line or paragraph where a tag was included inline?

For example, if I had a note with the following:

Sample text #tag1

Sample text #tag2

Sample text #tag1

Using dataview or some flavour of query I would like to show only the lines that include “tag1”
This way I could write anything in a daily note with appended tags and compile them into one location with queries.

It seems dataview isn’t going to work because it checks metadata and returns only the note title?
I understand you can use a simple “query” but I’ve found it messy and I really don’t need the note title, just the paragraph itself.

Using only dataview , aka DQL, you can’t get to the text of paragraphs and so on, and you need to enroll your own parsing within dataviewjs.

If you on the other hand switch to using lists, the task of collecting these items are a lot easier.

Try the following on for size:


- Sample text #tag1
- Sample text #tag2
- Sample text #tag3

```dataview
LIST WITHOUT ID item.text
FROM #tag2
FLATTEN file.lists as item
WHERE contains(item.tags, "#tag2")
```

In my daily notes I mostly use either pure lists or tasks lists to collect information, and I find it flows naturally with the lists as my thoughts tend to jump around a little, so that having them as logical units in separate items of the lists make sense to me.

Using task lists also allows for using custom statuses to further elevate what that specific items is about. And that makes me able to avoid using tags for marking up what the item is about.

  • Sample text #tag1
  • Sample text #tag2
  • Sample text #tag3
LIST item.text
FROM #tag2
FLATTEN file.lists as item
WHERE contains(item.tags, "#tag2")

So using this markup:

- [a] Kl 14 Meet that person
- [S] Buy groceries
- [!] Don't forget to post the thingy
- [ ] Just a normal task
- [/] A somewhat completed task

I can get this output:

image

This is almost perfect, and pretty much what I was looking for.
An added plus would be being able to click on the passage of text itself and go to the note, is that something that is possible?

If you’re using tasks, they do have that feature yes. You would then use a query like:

```dataview
TASK FROM #tag1
WHERE contains(tags, "#tag1")
```

No other solution, that I know of, offer the ability to click or even link back to the paragraph. That is, ordinary lists do offer to link to the enclosing section through usage of item.section (or potentially the block if the blockId has been assigned to that element).

That’s what I suspected. I’ll have to consider whether it’s a functionality I truely need, until then I might work on a cleaner way to see the note name in the output, perhaps in a table or something.

Many thanks for your help!

Do you need the note name in the TASK query, or in a LIST or TABLE query based upon list items?

Within the TASK query there is a nifty trick related to using visual, like in the following:

```dataview
TASK FROM #tag1
WHERE contains(tags, "#tag1")
FLATTEN file.link + ": " + text as visual
```

In other queries, you can also use file.link, or item.file.link after a FLATTEN file.lists as item, and similar constructs.

Maybe I’m missing something, but this is standard fare with core search:

I’m actually thinking using checkboxes and filtering by tasks might be better for my use case. It actually does everything I want it to. The only issue I’m having now is that images I’ve imported into obsidian aren’t displaying in the dataview query.

I’m using the standard format of ![[image.jpg]]
Is there a particular kind of query I need to include to I don’t need to change the convention for every image I’ve ever pasted into Obsidian?

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