Collecting all text under linked headings and allowing it be rendered as Markdown

What I’m trying to do

I am basically trying to do the same thing as here, but where instead of grabbing individual lines under the heading, it grabs and renders the whole header section as Markdown? The solution in the linked topic also isn’t able to grab text from subheadings under the grabbed linked heading.

Things I have tried

No solution found so far…

Also I have forgotten to provide an example of my use case for better clarity:

Example

## [[Sciences]]

### Heading 1

#### [[Heading 2]]

## Topic 1

# [[Topic 2]]

I have just thrown in the links as I sometimes link headers to ideas and don’t have any preference for one specific header level when it comes to this. What I want is to, for example, grab all the text under the ## [[Science]] header section (so not including Topic 1 or 2) for all my Daily Notes and render it as Markdown in the “Science” note.

Also found this resource. Best method I’ve found so far is to use the Text Expand plugin, combined with Templater, though that’s slightly hacky because a) the view isn’t autoupdating and b) I can’t seem to specify a directory for the text search. Ideally if anyone has a better understanding of Dataview or DataviewJS then a script would be an ideal solution. I am not 100% familiar with Javascript or Regex so a quick script rundown would be very much appreciated.

Thank you!

Hmm… I started doing some test related to this question, and made the following file named t73565:

## one

First main heading

### one_one

Sub heading of the first heading

### one_two
Second sub-heading of the first heading

## two

Second main heading

When I then do ![[t73565#one]] it includes all the sub headings. That is both the one_one and one_two heading, so does it not do that for you?

And in my test scenario doing the following dataviewjs also works just nicely:

```dataviewjs

dv.paragraph("![[t73565#one]]")
dv.paragraph("![[t73565#one_one]]")
dv.paragraph("![[t73565#one_two]]")
```

And the result of that is a list of the headings with text list a few times since the first included the other two:

  • one
  • one_one
  • one_two
  • one_one
  • one_two

Is this matching what you’re experiencing?

Depending on the answer of that we need to do some other matching and pairing of stuff, and possibly iterate on the app.metadataCache.getFileCache() of a file having outlinks to the linked heading you’re looking for. By the way, will the header (with subheaders) you want to include always be a link? Or could it be just text too?

It will always be a link, which seems to be the problem as there isn’t a clear way for me to grab a header that is also a link.