In general Dataview doesn’t extract content from a file, and more specific from any given section. However, if the content you want to extract is in a list, you might get retrieve only the items in that list under a given heading.
Try the following in a file of its own, and see if it makes sense to you:
---
Tags: f87155
compName: ACME
---
questionUrl:: http://forum.obsidian.md/t//87155
- at top
## Top of Mind
- first under heading
- second under heading
## End matter
- at end
```dataview
TABLE compName, myItems.text
WHERE file = this.file
FLATTEN list(filter(file.lists, (i) => meta(i.section).subpath = "Top of Mind")) as myItems
```
A short explanation of the query, first of all it limits itself to just that current file. This you’ll definitively want to change once you get the rest of the logic according to your wishes.
The magic happens in the FLATTEN
line which expands it expression into a new variable:
FLATTEN ... as myItems
– After doing the expression the result is stored inmyItems
list(filter(file.lists, (i) => ... ))
– This might seem a little counterintuitive, but after thefilter
has finished filtering thefile.lists
item by item, the results are returned as a list again. This is to counter theFLATTEN
natural behavior of splitting lists into their separate itemsmeta(i.section).subpath = "Top of Mind"
– Within the filter eachi
holds exactly one list item, and when we dometa(i.section)
we extract the information related to thesection
link of that item. This link is populated with a header link, so when we then extract thesubpath
option from this it matches the heading that this particular item belongs to. Change"Top of Mind"
to whatever heading you want, and you’ll get list items from that heading.
The query above works for list items (and similar stuff can be done with task lists), but it can’t be done with ordinary text within an ordinary DQL query. If you want to start extracting pure text, you’ll need to switch to using dataviewjs and do file reading by yourself.