• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1Table of Contents
2=================
3
4Summary
5-------
6
7Adds a Table of Contents to a Markdown document.
8
9This extension is included with the Markdown library since version 2.0.
10
11Syntax
12------
13
14Place a marker in the document where you would like the table of contents to
15appear. Then, a nested list of all the headers in the document will replace the
16marker. The marker defaults to ``[TOC]`` so the following document:
17
18    [TOC]
19
20    # Header 1
21
22    ## Header 2
23
24would generate the following output:
25
26    <div class="toc">
27      <ul>
28        <li><a href="#header-1">Header 1</a></li>
29          <ul>
30            <li><a href="#header-2">Header 2</a></li>
31          </ul>
32      </ul>
33    </div>
34    <h1 id="header-1">Header 1</h1>
35    <h1 id="header-2">Header 2</h1>
36
37Configuration Options
38---------------------
39
40The following options are provided to configure the output:
41
42* **marker**: Text to find and replace with the Table of Contents. Defaults
43  to ``[TOC]``.
44* **slugify**: Callable to generate anchors based on header text. Defaults to a
45  built in ``slugify`` method. The callable must accept one argument which
46  contains the text content of the header and return a string which will be
47  used as the anchor text.
48* **title**: Title to insert in TOC ``<div>``. Defaults to ``None``.
49* **anchorlink**: Set to ``True`` to have the headers link to themselves.
50  Default is ``False``.
51