Table of Contents like Typora

Finally, I was able to replicate the Table of Contents like it is done in Typora.
I modified the plugin “Automatic Table of Contents”, and now happier than ever.

Changes over main.js under the plugins folder:

Here:
image

Added this code:

  addTitle: {
    type: 'boolean',
    default: true,
    comment: 'Include a title Table of Contents',
  }, 

and here:

added/modified:

let markdown = getMarkdownFromHeadings(headings, options)

instead of

const markdown = getMarkdownFromHeadings(headings, options)

and

if (options.addTitle)  markdown = '## Table of Contents\n' + markdown

Finally, add the TOC block to your note:

```table-of-contents

```

No need to specify addTitle: true because it’s true by default.

It will looks like this:

By default addTitle is true. But you could change to false in the bloc.

I have already submitted a gentle pull request.

9 Likes

By the way, the author of the package has already included the code I suggested. Now the “Table of Contents” can be added after updating the plugin from Obsidian plugins. The string can be entered in markdown. For instance, I use title: ## Table of Contents. Pretty neat!