blacksmithgu / obsidian-dataview

A data index and query language over Markdown files, for https://obsidian.md/.
https://blacksmithgu.github.io/obsidian-dataview/
MIT License
6.94k stars 411 forks source link

Implement `title` field for first H1/H2 heading (if no title field exists) #2290

Open mdbraber opened 6 months ago

mdbraber commented 6 months ago

I'd like to be able to query the title of a Markdown document being the first H1 or H2 heading in the document. This is described in the comments of the Markdown parser: https://github.com/blacksmithgu/obsidian-dataview/blob/4829a8320044dd3bdc3eafa96d628ffc74bacfd6/src/data-model/markdown.ts#L22 - but is not (yet?) implemented. Would it be possible to implement this?

Related FR: https://github.com/blacksmithgu/obsidian-dataview/issues/29

mdbraber commented 6 months ago

For those who want a quick solution, update data-import/markdown-file.ts around line 67 and include

let title: string | undefined;
if (metadata.headings && metadata.headings.length > 0) {
    title = metadata.headings[0].heading;
}

and include title in the returned PageMetadata

SpocWeb commented 5 months ago

@mdbraber do you want to make your change into a Pull-Request?

I would propose to even add the full HeadingCache[] to the Page-Info, so we can query it for any number of problems.

SpocWeb commented 5 months ago

I think it is more value to provide the full Heading Info as demonstrated here: https://github.com/blacksmithgu/obsidian-dataview/compare/master...SpocWeb:obsidian-dataview:headings-in-PageInfo

mdbraber commented 5 months ago

Don't have time to do it right now; but I'll see if I can get to it later

SpocWeb commented 5 months ago

Try to have a look at my link above, because it covers all Headings. If you would second this, I would make it a PR.

mdbraber commented 5 months ago

Fine with me!