Table of Contents Generation
Markdom can automatically generate a Table of Contents (TOC) by analyzing the headings in your Markdown document. This is especially helpful for longer content, enabling users to navigate easily between sections.
How It Works
Section titled “How It Works”To insert a TOC, add the placeholder <!-- TOC-HERE -->
anywhere in your Markdown file. Markdom will replace this comment with a structured HTML navigation element based on the headings it detects.
Example
Section titled “Example”Input Markdown:
Section titled “Input Markdown:”# Introduction
<!-- TOC-HERE -->
## Getting Started
## Features
Output HTML:
Section titled “Output HTML:”<h1 id="introduction"> <a href="#introduction">Introduction</a></h1>
<nav class="markdown-toc"> <ul> <li><a href="#getting-started">Getting Started</a></li> <li><a href="#features">Features</a></li> </ul></nav>
<h2 id="getting-started"> <a href="#getting-started">Getting Started</a></h2><h2 id="features"> <a href="#features">Features</a></h2>
Output Structure
Section titled “Output Structure”The TOC is rendered as:
<nav class="markdown-toc"> <ul> <li><a href="#heading">Heading</a></li> <!-- More list items for each heading --> </ul></nav>