alto/commonmark-table-of-contents

CommonMark extension that generates a linked table of contents from document headings at @toc directives.

Maintainers

Package info

github.com/altophp/commonmark-table-of-contents

Homepage

Issues

Documentation

pkg:composer/alto/commonmark-table-of-contents

Transparency log

Fund package maintenance!

smnandre

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

v1.0.0 2026-07-30 02:00 UTC

This package is auto-updated.

Last update: 2026-07-30 02:56:58 UTC


README

Summary

A must-have for any document longer than a page. Place @toc where you want the contents list and the extension takes care of the rest: headings are collected, anchor IDs are assigned, and a navigable nested list is rendered -- with filtering by level and configurable output style.

Installation

composer require

composer require alto/commonmark

Registration

use Alto\CommonMark\Extension\TableOfContents\TableOfContentsExtension;
use League\CommonMark\Environment\Environment;

$environment = new Environment();
$environment->addExtension(new TableOfContentsExtension());

Usage

@toc
@toc {min: 2, max: 3, title: "Contents", style: ordered}

Configuration

  • min_level / max_level: heading level bounds.
  • style: bullet or ordered.
  • title, class, id, marker: output/customization options.

Minimal Example

# Guide
@toc {min: 2}

## Intro

## Setup

### Advanced Setup

Development

This extension is actively developed in the alto/commonmark monorepo.

License

MIT License -- Simon André & Alto