Nikola Table of Contents in Markdown format

196 Views Asked by At

I've installed Nikola (https://getnikola.com/) and have created a markdown file which gets displayed as a post successfully.

In my conf.py my markdown extensions look like this after install.

MARKDOWN_EXTENSIONS = ['markdown.extensions.fenced_code', 'markdown.extensions.codehilite', 'markdown.extensions.extra']

It seems like Table of Contents should be included by default so I enabled it

MARKDOWN_EXTENSIONS = ['markdown.extensions.fenced_code', 'markdown.extensions.codehilite', 'markdown.extensions.extra','markdown.extensions.toc']

and then added the text [TOC] to my markdown file which has a few sample headings

<!--
.. title: Witness the Quickness
.. slug: witness-the-quickness
.. date: 2020-10-26 18:46:36 UTC
.. tags: 
.. category: 
.. link: 
.. description: 
.. type: text
-->


[TOC]
Sample text with some headings below

# Well, Well well

## Duppy guides my hand

### The smiles on their faces

In the generated html file it just displays the [TOC] text. it does convert the #Headings into html headings, as expected but no table of contents.

Are there other settings that need to be changed / enabled to get this working?

1

There are 1 best solutions below

1
On

[TOC] must be in a paragraph of its own. Add a newline, like this:

<!--
.. title: Witness the Quickness
.. slug: witness-the-quickness
.. date: 2020-10-26 18:46:36 UTC
.. tags: 
.. category: 
.. link: 
.. description: 
.. type: text
-->


[TOC]

Sample text with some headings below

# Well, Well well

## Duppy guides my hand

### The smiles on their faces