Table of Contents

Configure the automatically generated table of contents sidebar for your Mordoc documentation pages.

Table of Contents

The table of contents (TOC) provides an at-a-glance overview of a page's structure and enables quick navigation to specific sections. Mordoc automatically generates the TOC from your page headings.

How TOC Works

The TOC is automatically generated from the heading structure of each page:

Markdown
# Page Title

## Section One
Content here...

## Section Two
Content here...

### Subsection 2.1
Content here...

### Subsection 2.2
Content here...

## Section Three
Content here...

This generates a TOC with all the headings, allowing readers to jump directly to any section.

Default Behavior

By default, the TOC:

  • Automatically generates from page headings
  • Shows Level 2 and Level 3 headings (## and ###)
  • Displays on the right side of the page
  • Highlights current section as you scroll
  • Sticky positioning - stays visible while scrolling
  • Hides on mobile - Shows only on tablets and desktops

The TOC is completely automatic. You don't need to manually create or update it—just write headings in your markdown and the TOC is generated.

Heading Levels in TOC

What's Included by Default

Heading LevelMarkdownIncluded in TOC
Level 1#✗ (Page title)
Level 2##
Level 3###
Level 4####
Level 5#####
Level 6######

Level 1 headings are used as the page title and don't appear in the TOC. Levels 4-6 are typically too detailed for the TOC.

Configuration

Customize TOC behavior through the configuration file.

Edit config/styles/main.json:

Json
{
  "toc": {
    "enabled": true,
    "minHeadingLevel": 2,
    "maxHeadingLevel": 3,
    "position": "right",
    "width": "240px",
    "title": "On This Page",
    "showOnMobile": false
  }
}

Configuration Properties

PropertyTypeDescriptionDefault
enabledbooleanShow/hide TOC globallytrue
minHeadingLevelnumberMinimum heading level to include (2-6)2
maxHeadingLevelnumberMaximum heading level to include (2-6)3
positionstringTOC position: "right" or "left""right"
widthstringTOC sidebar width"240px"
titlestringTOC heading text"On This Page"
showOnMobilebooleanDisplay TOC on mobile devicesfalse

Show More Heading Levels

To include Level 4 headings:

Json
{
  "toc": {
    "maxHeadingLevel": 4
  }
}

Show Only Major Sections

To show only Level 2 headings:

Json
{
  "toc": {
    "minHeadingLevel": 2,
    "maxHeadingLevel": 2
  }
}

Disable TOC

To disable the TOC completely:

Json
{
  "toc": {
    "enabled": false
  }
}

Per-Page TOC Control

Disable the TOC for specific pages using frontmatter:

Markdown
---
title: My Page
toc: false
---

# My Page

This page won't show a table of contents.

This is useful for:

  • Short pages that don't need a TOC
  • Landing pages with different layouts
  • Pages with custom navigation

Styling the TOC

Customize TOC appearance:

Json
{
  "toc": {
    "title": "On This Page",
    "titleColor": "#111827",
    "titleSize": "0.875rem",
    "titleWeight": "600",
    "linkColor": "#6b7280",
    "activeLinkColor": "#3b82f6",
    "hoverLinkColor": "#111827",
    "fontSize": "0.8125rem",
    "lineHeight": "1.75",
    "indent": "1rem"
  }
}

Style Properties

PropertyDescriptionDefault
titleColorTOC heading color#111827
titleSizeTOC heading size0.875rem
titleWeightTOC heading weight600
linkColorLink text color#6b7280
activeLinkColorActive section color#3b82f6
hoverLinkColorLink hover color#111827
fontSizeLink text size0.8125rem
lineHeightLink line height1.75
indentNested item indent1rem

TOC Behavior

Active Section Highlighting

As users scroll, the TOC automatically highlights the current section:

  • Scroll detection: Detects which section is currently visible
  • Active indicator: Current section is highlighted
  • Smooth transition: Color transitions smoothly between sections

Smooth Scrolling

Clicking a TOC link smoothly scrolls to that section:

  • Smooth animation: Not instant jump
  • Offset adjustment: Accounts for fixed headers
  • Focus management: Updates browser history

Sticky Positioning

The TOC remains visible while scrolling:

  • Fixed position: Stays in view as you scroll
  • Respects viewport: Scrollable if too long
  • Smart positioning: Doesn't overlap content

Best Practices

Writing TOC-Friendly Headings

Good headings:

Markdown
## Installation
## Configuration
## Usage Examples
## Troubleshooting

Poor headings:

Markdown
## Installation (This section explains how to install the software on your computer)
## Config
## Examples
## Problems You Might Encounter and How to Fix Them

Keep headings:

  • Concise (3-6 words ideal)
  • Descriptive
  • Parallel in structure
  • Consistent in style

Logical Heading Structure

Create a clear hierarchy:

Markdown
# API Guide

## Authentication
### API Keys
### OAuth Flow

## Endpoints
### Users
### Projects
### Files

## Rate Limiting
### Default Limits
### Custom Plans

This creates a scannable TOC that reflects your content structure.

Avoid Too Many Headings

Good (scannable):

Markdown
## Overview
## Getting Started
## Core Concepts
## Advanced Topics
## API Reference

Poor (overwhelming):

Markdown
## Section 1
## Section 2
## Section 3
## Section 4
## Section 5
## Section 6
## Section 7
## Section 8
## Section 9
## Section 10

Aim for 5-10 major sections per page.

Responsive Behavior

Desktop (> 1024px)

  • TOC visible in right sidebar
  • Fixed position while scrolling
  • Full width (default 240px)

Tablet (768px - 1024px)

  • TOC may be hidden or collapsible
  • Reduced width
  • Toggle button to show/hide

Mobile (< 768px)

  • TOC hidden by default
  • Accessible via dropdown or modal
  • Saves screen space for content

Configure mobile behavior:

Json
{
  "toc": {
    "showOnMobile": true,
    "mobilePosition": "dropdown"
  }
}

Accessibility

The TOC is built with accessibility in mind:

  • Semantic HTML: Uses proper navigation landmarks
  • Keyboard Navigation: Fully keyboard accessible
  • Screen Readers: ARIA labels for context
  • Focus Indicators: Clear focus states
  • Skip Links: Option to skip TOC navigation
Navigation Landmark

The TOC uses <nav aria-label="Table of Contents"> for proper semantic structure and screen reader support.

Use Cases

Long Documentation Pages

For comprehensive guides:

Markdown
# Complete User Guide

## Installation
### System Requirements
### Download
### Installation Steps

## Configuration
### Basic Settings
### Advanced Options
### Environment Variables

## Usage
### Getting Started
### Common Tasks
### Advanced Features

## Troubleshooting
### Common Issues
### Error Messages
### Support

The TOC helps users navigate long content efficiently.

API Documentation

For endpoint documentation:

Markdown
# Users API

## Overview
## Authentication
## Endpoints
### List Users
### Get User
### Create User
### Update User
### Delete User
## Error Codes
## Rate Limits

TOC provides quick access to specific endpoints.

Tutorial Pages

For step-by-step guides:

Markdown
# Build Your First App

## Before You Begin
## Step 1: Setup
## Step 2: Create Project
## Step 3: Add Features
## Step 4: Test
## Step 5: Deploy
## Next Steps

TOC shows progress through the tutorial.

Troubleshooting

TOC Not Showing

  • Check enabled: true in configuration
  • Verify page has Level 2 or 3 headings
  • Ensure page isn't too short (< 3 headings)
  • Check page frontmatter doesn't have toc: false

Headings Missing from TOC

  • Verify heading levels match configuration
  • Check heading markdown syntax is correct
  • Ensure headings aren't inside code blocks
  • Rebuild site: npm run build

TOC Not Highlighting Current Section

  • Check JavaScript is enabled
  • Verify scroll event listeners are working
  • Clear browser cache
  • Check for CSS conflicts

TOC Overlapping Content

  • Adjust TOC width in configuration
  • Check viewport size and responsive breakpoints
  • Verify page layout CSS
  • Consider hiding TOC on smaller screens

If you disable the TOC globally but want it on specific pages, you'll need to manage this through page-specific configuration or custom templates.

Examples

Basic TOC Configuration

Json
{
  "toc": {
    "enabled": true,
    "minHeadingLevel": 2,
    "maxHeadingLevel": 3,
    "title": "Contents",
    "position": "right"
  }
}

Detailed TOC (Include Level 4)

Json
{
  "toc": {
    "enabled": true,
    "minHeadingLevel": 2,
    "maxHeadingLevel": 4,
    "title": "Page Contents"
  }
}

Minimal TOC (Major Sections Only)

Json
{
  "toc": {
    "enabled": true,
    "minHeadingLevel": 2,
    "maxHeadingLevel": 2,
    "title": "Sections"
  }
}

Custom Styled TOC

Json
{
  "toc": {
    "title": "Jump To",
    "titleColor": "#059669",
    "activeLinkColor": "#059669",
    "fontSize": "0.875rem",
    "width": "280px"
  }
}

Next Steps