Toc (table of contents) level change for a specific post

Hi there,

I use jekyll_toc plugin to generate table of contents in all posts. I have the following configuration in my _config.yml file.

  - jekyll-toc
    min_level: 1
    max_level: 4

Above configuration works fine for all of my posts. But I needed a different toc level for some of my posts like level 1 and level 2 only.

Is there any way I could specify that in a post front matter?

Based on the look at the docs, you can only specify in the config and not per page.

What is the reason why some posts would have their TOC headings start at say 2 instead of 1? It would look weird when browsing across pages.

Also your question might be better for Issues of the repo (weird everyone there uses the plugin and the maintainers might reply) than the general Jekyll forum (where only some people will be familiar with it)

Note that gems is deprecated and plugins is the preferred key in the config of Jekyll. Installation

As an alternative, I like to use Markdown All In One extension in VS Code to generate TOC at the top of a page (works for any Markdown page not just posts and works for non-Jekyll too).

Use the command-prompt to insert the TOC initially at the top of the page. Then you have the TOC manually update or update automatically on page save.

The post title takes h1. That is level 1. So my post starts with sub headings h2, h3 and so on.

I asked there. The author seems not much active.

I know. I am using old version of Jekyll. Which is not compatible with the plugins I guess. But the migration takes time from old Jekyll to new Jekyll along with all plugins I am using…

Hmm. I will try this. Is there any plugin you are aware of for Vim. I am comfortable with Vim. Thanks

Can you just make all posts start at level 2 heading then for TOC? I don’t understand the need for customizing.

I don’t know vim plugins. The vim interface is clunky to me unless you spend a lot of time practicing shortcuts and using it regularly while an IDE is intuitive and easy to install plugins so i can switch between Pycharm and VSCode and Sublime with some ease while the skills aren’t so transferable to vim.

Consider using an independent tool like a CLI tool if one exists.

Or a website like this. So you copy and paste your content to generate your TOC

Instead of using the plugin you could try this _include which is written in pure Liquid.

Depending on how you drop it into your layouts, you could feed it page specific variables for h_min and h_max to change them per page.


Following the documentation you can exclude manually any header tag you want adding the no_toc class to the element.
To add a class in markdown you must use this sintax: {:.class_name} near the element.
So in the specific case you should have something like:

# This header is on toc

## this one too

### this is not in toc

## this neither

## this is

Though it doesn’t fulfill my requirement, thanks for the tip.

1 Like