Git Product home page Git Product logo

obsidian-plugin-dynamic-toc's Introduction

⚠️ Notice

I'm unable to find the time to keep this repository well maintained, and up-to-date with Obsidian. Life gets in the way. This plugin should be forked/rebuilt by someone who is willing to find the time to build a plugin that the Obsidian community deserves.

Obsidian Dynamic ToC

An Obsidian plugin to generate Tables of Contents that stay up to date with your document outline. Heavily inspired from hipstersmoothie/obsidian-plugin-toc

Foreword

This plugin attempts to parse your document headings and generate a markdown table of contents for them. There have been a handful of issues raised which are due to how people are using headings. Headings offer a lexical structure to a document, they are not intended to be used for style.

The following is an example of inconsistent heading depth. Instead of a level 4 heading it should be a level 3 heading.

## Level 2

#### Level 4

The following is an example of consistent heading depth. After a level 2 heading the next level is 3

## Level 2

### Level 3

👉 You can of course choose to structure your documents as you wish, but this plugin may not work effectively. I do attempt to make some exceptions but I will hide them behind settings to not interfere with peoples work flows, reduce stability, and to keep development time low. See Inconsistent Heading Depth

Usage

Code Block

It's really simple to use, just add a code block to your document:

👉YAML does not support tabs, only use spaces (source)

Defaults

```toc
style: bullet | number | inline (default: bullet)
min_depth: number (default: 2)
max_depth: number (default: 6)
title: string (default: undefined)
allow_inconsistent_headings: boolean (default: false)
delimiter: string (default: |)
varied_style: boolean (default: false)
```

Example

```toc
style: number
min_depth: 1
max_depth: 6
```

You can specify the options on a case-by-case basis in your documents, or you can override the defaults in settings. If you have settings you always want to use, your usage just becomes:

```toc

```

Inline Style

Inline styles render the highest level of heading such as H2 ## Heading 2, you can couple this with the delimiter option to generate a breadcrumbs like effect for your headings.

See Feature Request: Inline Links

Varied Style

Varied style allows for setting the topmost level of your headings, and the rest of the levels to the opposite style.

For example if you have varied_style set to true and your list style is bullet, the first level will be bullet and the subsequent headings will be number style.

Style: Bullet

Style: Number

See Feature Request: Mixed List Style

External Rendering Support

You can also add custom injection for compatibility with markdown readers such as Markor or Gitlab with the External Rendering Support setting. Such as:

  • [toc]/[TOC]
  • Or [[_TOC_]]

This feature is to allow for consistency with another tool of your choice such as GitLab.

If you have another convention that is required for a markdown reader of your choosing. Create an issue with the name of the viewer and the convention that's used.

Support All

You can skip individual selection and support all renderers by checking "Support all external renderers" in settings.

! If you add a new line between each identifier, you will get a new table of contents for each

[/toc/]

{{toc}}

[[__TOC__]]

[toc]

! If you add them all next to each other you will get a single block

[/toc/]
{{toc}}
[[__TOC__]]
[toc]

Insert Command

You can insert a table of contents by using the command palette and selecting "Insert table of contents" and selecting the table of contents to insert

Insert command

Table of contents options. Note that you will only see:

  1. "Code Block" if you have no external renderers set in settings
  2. "Code Block" and a single external renderer if set in settings
  3. All possible options if you have "Support all external renderers" set in settings

Remember you can set a hotkey in Obsidian for this command for even faster access.

Titles

You can add a title to every injected table of contents by using the Title option in setttings or inline inside a codeblock for example:

```toc
title: "## Table of Contents"
```

⚠️ If you are adding Markdown syntax to your title in the code block, you must wrap it in double quotes.

Inconsistent Heading Depth

As mentioned in the foreword above, this is not recommended, but there is a setting you can enable which will try and support you the best it can.

Given a heading structure such as:

## Level 2

#### Level 4

##### Level 5

## Level 2

### Level 3

With this option enabled, it will produce the following table of contents:

⚠️ Notice that the Level 4 and Level 3 headings are at the same depth

Contributing

yarn install

Development

To start building the plugin with what mode enabled run the following command:

yarn dev

Releasing

To start a release build run the following command:

yarn release
git push --follow-tags origin main

obsidian-plugin-dynamic-toc's People

Contributors

aidurber avatar future0906 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

obsidian-plugin-dynamic-toc's Issues

Is there a way to have TOC start with a single # and not the double ##?

Hello and thank you for developping this. I just moved from Joplin, and there I had most of my title start with a single pound sign. My TOC there would pick this up as the first title but here I need two to have it recognized. Is there a way to change this behavior?

Example:
Joplin this would be

First Title
Second

/# First Title

/## Second

But on Obsidian I get

Second

/# First Title

/## Second

support the pane view

Thank you for your awsome work.
Will this plugin support pane view in the future?

If not, may I make pull request to suppot it?

Forcing tight newline-spacing in TOC

Hello,

I have a small question, as the code you use in your reame

image

doesn't seem to work on my end. Fresh install, settings are the following:

image

This is the result on my end:

image

I'd like to condense it - because otherwhise this can easily become very large on certain notes. I don't need the newlines inbetween entries.

Is that possible/Why do I get different results?


Sincerely,
~Gw

Skip headings in toc

Is it possible to skip the first n headings in the toc?

Many of my documents look somewhat like this (in this case I would like to exclude "This is the document title" and "Table of contents" from the toc):
image

My source looks like this:

# This is the document title
#TheseAreDocumentTags

# Table of contents
```toc
    style: bullet
    min_depth: 1
    max_depth: 3
```

# First topic
## Subtopic 1

## Subtopic 2

# Second topic

Add entry for command palette

I keep forgetting how this TOC is embedded (on other platforms I need to use [[TOC]] or others)

So I think - especially for users new to markdown - it would be great to be able to open the 'Command Palette' and add the TOC-entry like that.

It could also give an additional entry to help with the options, but I don't have an idea how that could be realized (except by pasting all options as comments)

Additional rendering support requests

DEVONthink uses this format for table of contents -- please support it:

{{toc}}

TheBrain uses this format for table of contents -- please support it:

[/toc/]

Using dynamic toc causes some parts of the file uneditable

I have a file in which I am using headings and sub-headings as well as images. When using the dynamic toc to generate a table of contents at the top, some bulleted and indented bulleted text was rendered uneditable. I wasn't even able to select the text. the cursor would just jump to the last part of the last heading in the page

Navigating to heading with keyboard

I use Obsidian with keyboard only. When I navigate my cursor to the TOC it changes into the code block, making it impossible to jump to the heading i want.

Any ideas how to do this? Thanks.

Markdown in headings rendered as plain text in TOC

I noticed this using [[_TOC_]], but earlier today I switched to the code block syntax and updated to the latest plugin version, and I'm still seeing the behavior... below screenshots are with the code block syntax and plugin v 0.0.26

image

screenshots of the bug:

image

image

Generate TOC for "only this header" or "after TOC block"

Sometimes one section gets long enough that it's hard to read, or maybe we would like an overview of the sub headings headings.

For example:

# Intro
blah blah blah...

# Section One: taking over the world
So what is this section about.... blah blah blah...

```toc
this_heading_only: true
```

Something else, blah blah blah

## First Point
abc

## Second Point
xyz
### Second.a
zzz

# Section 2
...

Or the example of "After TOC Block"

# The thing
This is the thing...

Here's the nav of the rest of the note:
```toc
after_this_block: true
```

# One
## One.one
# Two
## Two.two

Is this possible to do/add?

generate a separate toc for each topics

I want to put multiple topics in one note, which means that one note contains multiple note contents, and separate lines are used between multiple notes. When I want to generate toc for multiple notes, inline mode always generates all toc, which is not what I want. I want to generate a separate toc for each note.Or from another point of view, generate toc only for the current title and subordinate titles

my note like this

## github

### proxy
### stars project


----

## vim

### plugin
### vimrc

Feature request: Inline links

Love this!

Just wondering if it would be possible to add an inline option to the styles? This would render a navbar style ToC, something like this:

Item 1 | Item 2 | Item 3 | Item 4

Perhaps let people specify the delimiter, too?

Here is what the header of my daily notes look like. The to-do and notes links are generated by dynamic toc. You can see why I immediately wanted an inline ToC. :)

Many thanks!

2022-02-02_01

Duplicating numbers

First of all thanks for a very useful, yet beautifully simple to use plug-in.

Before installing it I had the number headings plug-in installed, which adds numbers to the headings in the text. Those numbers are then also shown in the Outline pane, useful for navigating long notes with many headings, which my main vault consists of.

When I add a ToC at the top of a note with your plug-in, those pre-inserted numbers, which are part of the heading, also appear in 'your' ToC, thus duplicating the numbers.

image

Now, I don't know whose issue this is, so I have also asked about this on the other plug-in's Issues page.

Both plug-ins are very useful for me, and very easy to use.
Please advise.

Dynamic Table of Contents: styles.css not found

Dynamic table of contents version 0.0.15

app.js:1 GET https://github.com/aidurber/obsidian-plugin-dynamic-toc/releases/download/0.0.15/styles.css 404
m @ app.js:1
(anonymous) @ app.js:1
window.ajaxPromise @ app.js:1
t.ajaxCorsBypass @ app.js:1
(anonymous) @ app.js:1
(anonymous) @ app.js:1
(anonymous) @ app.js:1
s @ app.js:1
Promise.then (async)
l @ app.js:1
s @ app.js:1
Promise.then (async)
l @ app.js:1
s @ app.js:1
Promise.then (async)
l @ app.js:1
s @ app.js:1
Promise.then (async)
l @ app.js:1
s @ app.js:1
Promise.then (async)
l @ app.js:1
s @ app.js:1
Promise.then (async)
l @ app.js:1
(anonymous) @ app.js:1
o @ app.js:1
t.installPlugin @ app.js:1
(anonymous) @ app.js:1
(anonymous) @ app.js:1
(anonymous) @ app.js:1
(anonymous) @ app.js:1
o @ app.js:1
(anonymous) @ app.js:1
(anonymous) @ app.js:1
(anonymous) @ app.js:1
(anonymous) @ app.js:1
(anonymous) @ app.js:1
o @ app.js:1
cn @ app.js:1
(anonymous) @ app.js:1
(anonymous) @ app.js:1
app.js:1 Dynamic Table of Contents: styles.css not found
VM339:2 Dynamic TOC Loaded

The headers do not render correctly when the whole hierarchy is not respected.

Yes it is very bad to skip a level of heading !
But if I can, I do it ! And the official obsidian plan view render it properly...
Example, for this document :

## Level 1
Bal bla bla
#### Level 3
Bla bla bla too

Note that the ### Level 2 heading is skipped.

The dynamic toc render this :
o Level 1 - Level 3

Thanks for your plugin, it's very useful.

Spacing issue in live preview mode

When using Obsidian's new Live Preview edit mode, the table of contents is way more spaced-out when compared with reading mode (to an uncomfortable degree in my opinion). My expectation is that the TOC should look more-or-less the same spacing-wise between live preview and reader mode. Lists generated by other plugins (e.g. Dataview) do not exhibit this problem for me.

I've included a screenshot showing the same file in edit mode (source), edit mode (live preview) and reader mode:

Screenshot from 2022-01-02 14-44-19

Things I've tried (without success):

  • Switching-back to the default theme
  • Disabling all CSS snippets
  • Disabling all other plugins

I'm running Obsidian v0.13.17 (installer v0.13.14) on macOS and Linux. I've observed this behaviour throughout the v0.13.x release cycle.

Want to indent TOC levels without bullets or numbers

I want my TOCs to use indented levels, without bullets or numbers. Like this:

Level 1
....Level 1.1
.... ....Level 1.1.1
Level 2
.... Level 2.1

(The dots represent space; I'm not looking to show the dots in real life.)

I don't care if tabs or spaces are used. I cannot see a way to make this happen in the Dynamic TOC settings. I'm using the Minimal Style and the Style Settings Plugin, so maybe there's a way there. I'm just looking for a starting point for setting this up.

(It sure seems to me that Dynamic TOC used to work this way and then something changed; but that might just be false memory.)

Conflict with dataview?

After installing version 0.0.15, pages with dataview blocks don't update or don't display preview at all.

incorrect linking to headings with same name

first off, love the plugin

If I have (sub)headings with the same name eg

Heading A

Subheading a

Heading B

Subheading a

clicking on the TOC link for #B##a takes me to #A##a. This is an obsidian default linking thing where it just goes by heading name and has been brought up in the forum before (although I couldn't find it just now). The response was that best practice is to have unique header names and if you really need to you can link specifically to #B##a (their reasoning being that how far should you go up the path and links could get really long). But I was wondering if it could be an option for TOC links to contain the full heading info (ie #A##a and #B##a instead of just ##a) and thus would take you to the correct section?

Having a jumps in heading levels ruins the indentation

For example. I like to embed the TOC and some dataview metadata stuff at the top of my notes in a lvl4 heading so that I can fold it out of the way. But if I do that all the indentation above the lvl 4 get removed.

Support for Headers Within Lists

Most - if not all - of my notes are structured as follows:

image

Non-headed items are not processed by the plugin - as expected. However, to get around this limitation, I have tried the following:

image

Which did not yield any results as you can clearly see there:

image

Therefore, I would really appreciate it, if you could implement support for this use-case.

FR: Mixed List style

Thanks for this plugin! I was about to write a longer dataviewjs query, but this plugin does the job much better anyway :)

I was wondering, is it possible to have an option in the settings / code block for mixed list styles? e.g. H2 numbered, but H3 bullets?

FR: Wikipedia style lists.

I really like the Number list style, but I wonder if it would be possible to have it in the Wikipedia style, where you have 1. for your main entry, and children would be prefixed with 1.1, 1.2, etc. I've attached an image for reference

Number(Wiki style)

Table of contents rendered for active pane, not the note it is for

Since upgrading to obsidian 13.30 the plugin renders the table of contents for whichever note is active, not the note it is intended for.

To reproduce:

Add the table of contents to a note. Open another note in a new pane and switch to it. The table of contents will now show the headings from the active pane. Switch back to the note that has the toc and the headings switch back.

If you click on one of the links in the toc while the other document is active the toc reverts to its proper links (the ones from the intended document) and work as expected.

Tested in the help vault.

Let me know if I can help debug.

Incorrect formatting when heading is an internal link with a custom name

Obsidian provides support for creating internal links and displaying text for this link that is different to the name of the note you are linking to.
For example:
[[Example Link]] renders as Example Link, and links to the file "Example Link"
[[Example Link|Alt Text]] renders as Alt Text, but links to the same file, "Example Link".
This is useful for creating readable links where the actual note file may have a long and complex name.
Unfortunately, when I create a heading entitled [[Example Link|Alt Text]], dynamic-toc renders it as Alt Text|Example Link|Alt Text which kind of defeats the point of using these kind of internal links in the first place.
Here's a screenshot to show what I mean:
dynamic-toc-issue
Apart from this, the plugin works amazingly, so hats off to Aidurber for this great work.
Any resolution would be greatly appreciated!

Plugin no longer working

Has something changed recently that could cause the plugin to no longer work? I tried the examples and none of then generate a TOC when I switch to preview for the page/note. It used to work great.

Funky Live Preview

Live Preview has done a number on this plugin. Code Blocks kinda work but things get weird when you start having split panes. It behaves like a shared instance of the post processor between leafs, in version 12 each leaf would have its own instance. All issues due to Live Preview are on hold, the recommended course of action is to build a Code Mirror 6 extension. I estimate this taking a significant amount of time and completely rebuilding this plugin. That's not something I can justify for a hobby project.

The post processor isn't guaranteed to run inside live preview. I can get it to run if I have a codeblock processor. Go figure.

Because of the way content is output in code mirror, a renderer such as [TOC] doesn't appear in the document like that. In full preview mode [TOC] can be found in the document verbatim, in live preview there is some code mirror shenanigans. See below:
image

Image of bug
image

Conclusion

I'm unsure how to fix this, live preview has broken this plugin in a couple of different ways. I'm going to let the dust settle on live preview and see what solutions the community comes up with.

Add option to switch between Obsidian and Github styles

Thank you for the plugin, it's awesome!

I often work on Github docs and modified the plugin to support Github-styled TOC ([Some header](# some-header)).
I think it would be nice to have an option to switch between Obsidian and Github styles.

Possible to recognize whatever TOC convention appears in the document

@Aidurber added a couple of useful conventions for TOC markup.

I wonder if it would be possible if the plugin would add a TOC when any of the recognized conventions were present in the document. So, if I imported a file from DEVONthink and used the DEVONthink {{toc}} syntax it would be recognized, and then if I imported a file from some place else that used a different syntax, then the plugin would recognize that. This way we wouldn't have to be limited to just one configured convention. This would make the plugin "universally" functional.

TOC rendering at the bottom of the document when exported

Placing [TOC] at the top of the document renders the table of contents as expected, however when exporting as a pdf, drops it to the bottom of the document. Is it possible to render the table of contents at the top of the document as expected?

Suggest adding an option to turn off automatic directory updates.

Suppose currently note A is open, dynamic-toc is used at the beginning of note A
plug-in. Note B is referenced in note A. Suppose there are many headings in note B. When the mouse hovers over note B, the page will keep bouncing. So it is recommended that you add an option to turn off automatic updating of the table of contents.

TOC of external page

Hi!
It would be nice to have the option to set the root markdown file for the TOC.
example in file overview.md you could have:

# Overview

```toc
file: [[chapter_one]]
```

```toc
file: [[chapter_two]]
```


since in the example above the links to chapter_one.md and chapter_two.md would not be automatically updated by Obsidian – would it be an option to also have an option to add the TOC with the callout syntax? This would automatically update the wiki links.
Like:

# Overview

> [!TOC] Table Of Contents Chapter 01
> file: [[chapter_one]]


> [!TOC] Table Of Contents Chapter 02
> file: [[chapter_two]]

Mathjax Issues

I think this is one of the best plugins but I'm not sure I'm using it correctly.

I tried using it on a few of my notes (where I had MathJax in the headings) and it didn't seem to work.

image

Apparently I should not be using MathJax in headings where they are interpreted as is and displayed as per Mathjax Format.

Embedded notes shows parent's Dynamic Table of Content

As the title state, if an embedded note have a DoC, it's the parent's DoC that is injected on top of the embedded note instead of the embedded note DoC itself.
Also, an option to hide embedded notes DoC would be cool.

Subheading links are not indenting under higher Headings in toc

I just started to use this plugin, but I tried it on a few of my notes and found that it did not indent subheadings under top headings.
ScreenShot_2022-04-24_103157@2x

Each of these docs have levels of headings underneath each other, and would expect that a link to an ## h2 would be indented below a # h1 heading. In most of the examples I seen for this plugin, it seems to be the case, but is not working for me.
ScreenShot_2022-04-24_103654@2x

I checked all viewing modes, and there is no indenting on any of them. Do I need to apply a setting or a certain style or is this a bug?

*Edited to include Source code view of notes to give better context

Bug: [[_TOC_]] doesn't work

Trying to get the [[_TOC_]] syntax working (which is mentioned in the readme) for compatibility with azure wikis, but it doesn't seem to work. Also in the settings menu it doesn't appear as an option, but looking at the source it appears to be mapped to TOC but still doesn't seem to work
image

Obsidian: 0.12.19
Plugin: 0.0.16
OS: MacOS Big Sur

Tab and space difference in code blocks

Hi

Look at the following example:

```toc
	style: number
	min_depth: 1
```

If the indentation for options is made from a tab character, this isn't parsed at all and resorts to the default values. However, if the identation is made from spaces(4 spaces, for example), it gets parsed and works.

Is this expected?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.