Table of Contents
Sheriff automatically generates a Table of Contents (TOC) for your pages.
You don't need to write it yourself.
Whenever Sheriff builds a page, the Scout module scans your rendered Markdown for headings and builds a linked table of contents automatically.
The Big Picture
The process is completely automatic.
Markdown │ ▼ Headings │ ▼ Scout scans the page │ ▼ Anchor links generated │ ▼ Table of Contents generated
Markdown │ ▼ Headings │ ▼ Scout scans the page │ ▼ Anchor links generated │ ▼ Table of Contents generated
If your theme includes a TOC slot, Sheriff will automatically inject the finished Table of Contents into the page.
Supported Heading Levels
Scout currently includes the following heading levels:
# Heading 1 ## Heading 2 ### Heading 3 #### Heading 4
# Heading 1 ## Heading 2 ### Heading 3 #### Heading 4
Each heading becomes an entry in the Table of Contents.
Automatic Anchor Links
Sheriff automatically generates anchor links for every supported heading.
For example:
## Installing Sheriff
## Installing Sheriff
becomes something similar to:
<h2> <a id="installing-sheriff"></a> Installing Sheriff </h2>
<h2> <a id="installing-sheriff"></a> Installing Sheriff </h2>
The generated Table of Contents then links directly to that anchor.
No additional configuration is required.
Footnotes
If your page contains footnotes, Scout automatically adds a References & Footnotes entry to the end of the Table of Contents.
This makes long technical articles much easier to navigate.
Theme Integration
Layouts never generate the Table of Contents themselves.
Instead, they contain a slot.
For example:
{{{SLOT::SIDEBAR_MAIN}}}
{{{SLOT::SIDEBAR_MAIN}}}
Your theme's templates.yall file can then assign the Scout TOC token to that slot.
When Sheriff builds the page:
- Scout scans the headings.
- Scout generates the HTML for the Table of Contents.
- Stagehand injects the generated TOC into the appropriate layout slot.
This means you can move your TOC around wherever you want it.
Modules Involved
The following modules participate in Table of Contents generation:
- Scout — scans headings and generates the Table of Contents.
- Stagehand — injects the generated TOC into the layout.