Self-Upgrading In Document Table of Contents Plugin

It would be nice to have inbuilt, within Obsidian, a Table of Contents (TOC) tool that self-upgrades / automatically upgrades, such that changes in headings are captured and rendered.

It’s disappointing that Obsidian lacks such a basic tool.

Existing plugins for this aren’t getting the job done.

The Dynamic Table of Contents (DToC) plugin is no longer giving usable results (GitHub - Aidurber/obsidian-plugin-dynamic-toc: An Obsidian plugin for creating Tables of Contents that stay updated with your document).

I posted about this recently, to ask for a temporary workaround (here: Dynamic Table of Contents Buggy and No Longer Working Well).

I’m aware that DToC is now archived. And in its archived form, it’s not useful.

For instance, headings’ indentation and varied levels aren’t being reflected in the table of contents that it creates. As a result, when applicable, one can’t see which headings are others’ subheadings. DToC now shows all headings as being on the same level, when that’s not the case (I have Obsidian version 0.16.5, and it created this problem well before this version).

The older plugin that came before DToC isn’t dynamic and therefore cannot automatically upgrade its contents when changes are made --forcing users to waste time constantly recreating TOCs.

A plugin that (1) preserves and shows the different levels of headings within a document and (2) automatically upgrades any created TOC’s content when heading changes are made would not only be nice but crucial. MS Word even does this well.

3 Likes

Not the solution to your FR but might be interesting: There is a ‘Floating TOC’ plugin currently in code review. I installed it already using BRAT.

1 Like

Thank you for mentioning it.

It still doesn’t address the fact that creating TOC’s isn’t an inbuilt feature.

And why is that a big problem?

Because (1) the ability to create TOC’s is a crucial and fundamental capacity (that’s available in MS Word and many classic word processors) and (2) many Obsidian plugins undergo neglect.

For instance, this plugin “had not been updated for a long time” and is available only through BRAT.

This might be an obvious question, but have you turned on ‘Outline’ in core plugins?

Sidenote: Floating TOC is not out yet, but probably will be soon.

1 Like

Why not just use Dataview? It’s simple, functional, and automatically updates.

Create a toc.js file in the root of your Obsidian vault, with this contents:

// Set this to 1 if you want to include level 1 headers,
// or set it to 2 if you want to ignore level 1 headers
const startAtLevel = 2
const content = await dv.io.load(dv.current().file.path)
const toc = content.match(new RegExp(`^#{${startAtLevel},} \\S.*`, 'mg'))
  .map(heading => {
    const [_, level, text] = heading.match(/^(#+) (.+)$/)
    const link = dv.current().file.path + '#' + text
    return '\t'.repeat(level.length - startAtLevel) + `1. [[${link}|${text}]]`
  })
dv.header(2, 'Table of contents')
dv.paragraph(toc.join('\n'))

And then in any note which you wish to add a dynamic TOC, you just add this code:

```dataviewjs
dv.view('toc')
```

3 Likes

I understand what the OP is asking but I don’t see this as a core feature.
Renamed and Moved to plugin ideas.

1 Like

I, too, would like to make use of a [[TOC]] block that automatically updates based on my document’s contents. I’ve grown accustomed to it in things like Azure DevOps Wikis. Also, unfortunately, GitHub - Aidurber/obsidian-plugin-dynamic-toc: An Obsidian plugin for creating Tables of Contents that stay updated with your document stopped working for me, as of 1.0.0. :sob:

Definitely going to give the Floating TOC a try, as well as Dataview.

Just wanted to add my comment here so that OP knows they are not alone…and I joined these forums to post that.

Also, Obsidian is changing my life. Thank you!

1 Like

I also agree that [TOC] rendering is a useful feature

1 Like

i forgot to mention, there is also the “Quiet outline” plugin which renders a prettier TOC than the built in outline.

1 Like

I’m +1 on this plugin Idea. I’d love to have a Table of Contents outline that is automatically updated in my document. It’s a useful feature in other note apps and I’m glad to see it being addressed here.

And, I agree this feature is perfect for a community or core plugin.

Update
I just found the core plugin Outline and it does what I was looking for. When turned on there is a document outline / Table of Contents based on headers in the left panel. If I click on the outline heading in the panel, the cursor jumps to that position in the main window document. Perfect.

I think the updating automatically is the issue, but I just close and reopen the doc to update the outline. Thanks

The core outline plugin should update in real time I thought.

If you want a TOC in the note itself, I just stumbled over this awesome Dataview solution: