Table of content (TOC)

Thanks, how can I get .mde-preview element to do a XX.getElementById("YY").scrollIntoView()?


  • XX: Use JavaScript API
  • YY: Find a remark plugin to add slugs to headings

Plugin coded, you can now generate table of contents by adding ‘table of contents’ or ‘toc’ to your markdown file.

Do you have some code reviews advices?

Great job! I noticed the following:

  • Can you store a reference to the default behavior for MDEPreview.remarkReactOptions.remarkReactComponents.a in a variable and set it back on deactivation?
  • Scrolling using native JS instead of Jquery
  • Package name should be toc instead of inkdrop-toc

Looking forward to using your plugin!

1 Like

Thanks @anon29127703,
I removed jquery import but still using it (as jquery is part of electron inkdrop app) to keep animated scroll.
I rename package to toc
Not sure how to set back MDEPreview.remarkReactOptions.remarkReactComponents.a what would you do based on my code I tried something by I do not know if it will work.

Great work!
BTW, I will remove user-content- prefix in the next version so that TOC links in exported HTML works as well.

Not sure how to set back MDEPreview.remarkReactOptions.remarkReactComponents.a

Just restore the original A value:

this.MDEPreview.remarkReactOptions.remarkReactComponents.a = this.OrigA

I’m planning to remove jquery from the app dependency in the future. So I would encourage using vanilla JS API.


  • jQuery removed, I now use pure Vanilla
  • remarkReactComponents.a is restored now (I think)

OK for user-content-, let me know when it’s removed.


Thanks @anon956856!

The TOC plugin author has unfortunately deleted his account. So I decided to take it over.
It is now an official plugin!
The plugin v2.0.3 is out, which supports Inkdrop v3.20.2:

I’m using inkdrop in two different MacBook Pros, in one of them toc is working perfectly fine, in the other it is not working. Any suggestions on what to check to get it running on the computer where it does not work?

Hi Julio,

Please try updating the plugin with:

ipm update

Hi Takuya! Thanks for the quick reply, ran ipm update, was already running on latest version :confused:


That’s weird. You have also the plugin installed on the another MBP, right?
If so, please tell me if any error happens. You can check it on the console from Developer -> Toggle Developer Tools.

Found out what the issue was. TOC only works if there is at least one Header1 item (#) and my document had only Header2 items (##). That’s why it wasn’t generating one. Not sure if that is the expected behavior but it’s clear now why it wasn’t working!

Thanks a lot for the attention though, loving Inkdrop on a daily basis!

Yes, that’s the expected behavior.
Here is how remark-toc works:

  • Looks for the first heading containing 'Table of Contents' , 'toc' , or 'table-of-contents' (case insensitive, supports alt/title attributes for links and images too)
  • Removes all following contents until an equal or higher heading is found
  • Inserts a list representation of the hierarchy of following headings
  • Adds links to following headings, using the same slugs as GitHub

Hope that helps!

1 Like

Thank you for the your response and all other commends
I’ve installed toc and updated all plugins as suggested by before then and still didn’t work

# Table of Contents

## H2


### H3


#### H4


You should write a h2 heading for Table of Contents:

## Table of Contents

Thanks @craftzdog for your response. It didn’t work for me either

## Table of Contents

## H2


### H3


#### H4


1 Like

As of TOC doesn’t working even with putting it in H2 heading. Is there any way to get a heading link to build the TOC manually?

Also, Is there a way to get a like for a notebook? I have notebook with sub notebooks



Please provide me a reproduction code.
If you have any issue, please create a separate issue as this topic has been already resolved.
Notebooks are always sorted in alphabetical order so you have to rename notebooks to sort.
I’m going to lock this topic.