Skip to content

Commit 90b744e

Browse files
docs: Add documentation for HeadingPlugin and TOCPlugin (#246)
Co-authored-by: sourcery-ai[bot] <sourcery-ai[bot]@users.noreply.github.com> Co-authored-by: Fabian Braun <[email protected]>
1 parent 1d6a629 commit 90b744e

File tree

2 files changed

+127
-0
lines changed

2 files changed

+127
-0
lines changed

docs/source/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ Contents
8383
custom_components
8484
grid
8585
components
86+
plugins/toc
8687
how-to/index
8788
reference
8889

docs/source/plugins/toc.rst

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
##############################
2+
Headings and table of contents
3+
##############################
4+
5+
*********
6+
Heading
7+
*********
8+
9+
The Heading plugin allows you to add headings (h1-h6) to your content with optional styling and anchors for navigation.
10+
11+
Configuration
12+
*************
13+
14+
- **Heading Level**: Choose h1-h6 for the heading tag
15+
- **Heading Text**: The text content of the heading
16+
- **Heading ID**: Optional anchor ID for TOC linking
17+
- **Heading Alignment**: Text alignment (left, center, right)
18+
- **Heading Context**: Optional Bootstrap contextual class for styling
19+
20+
Example
21+
=======
22+
23+
Basic heading::
24+
25+
<h2 id="my-section">My Section Title</h2>
26+
27+
To create a heading that will appear in a table of contents:
28+
29+
1. Add a Heading plugin
30+
2. Set the heading level (e.g., h2)
31+
3. Enter your heading text
32+
4. Set a unique ID in the "Heading ID" field
33+
5. Optional: Adjust alignment and styling
34+
35+
Advanced Usage
36+
=============
37+
38+
Styling
39+
-------
40+
41+
You can apply Bootstrap contextual classes through the "Heading Context" setting:
42+
43+
- primary
44+
- secondary
45+
- success
46+
- danger
47+
- warning
48+
- info
49+
- light
50+
- dark
51+
52+
For example, selecting "primary" will add the ``text-primary`` class.
53+
54+
TOC Integration
55+
--------------
56+
57+
To make a heading appear in a Table of Contents:
58+
59+
1. The heading **must** have an ID set
60+
2. The TOC plugin must be placed **after** the heading in the content flow
61+
3. Only headings with IDs will appear in the TOC
62+
63+
*******************
64+
Table of Contents
65+
*******************
66+
67+
The Table of Contents (TOC) plugin automatically generates a navigation list from headings in your content.
68+
69+
**Important**: The TOC plugin must be placed **after** the headings it references in the content flow.
70+
71+
How it Works
72+
============
73+
74+
The TOC plugin:
75+
76+
1. Scans for Heading plugins that appear before it in the content
77+
2. Collects headings that have an ID set
78+
3. Generates a nested list of links to those headings
79+
80+
Basic Usage
81+
===========
82+
83+
To create a table of contents:
84+
85+
1. Add your Heading plugins with IDs set
86+
2. Add the TOC plugin after the headings
87+
3. The TOC will automatically generate when the page renders
88+
89+
Positioning at Top of Page
90+
==========================
91+
92+
Since the TOC must be placed after headings to collect them, use grid layouts to display it at the top:
93+
94+
Two Column Layout Example
95+
-------------------------
96+
97+
1. Create a container
98+
2. Add a row with two columns
99+
3. In the first (left) column:
100+
- Add the TOC plugin
101+
4. In the second (right) column:
102+
- Add your content with Heading plugins
103+
5. Set column widths appropriately (e.g., 3/9 split)
104+
105+
Example Structure::
106+
107+
Container
108+
└── Row
109+
├── Column (col-3)
110+
│ └── TOC Plugin
111+
└── Column (col-9)
112+
├── Heading Plugin
113+
├── Content...
114+
├── Heading Plugin
115+
└── More content...
116+
117+
This creates a sidebar layout with the TOC always visible while scrolling through content.
118+
119+
Best Practices
120+
==============
121+
122+
1. Always set IDs on headings that should appear in the TOC
123+
2. Use consistent heading levels for proper hierarchy
124+
3. Keep heading IDs unique across the page
125+
4. Consider using the grid layout pattern for better UX
126+
5. Test navigation on both desktop and mobile views

0 commit comments

Comments
 (0)