Sphinx extension that extends local ToC with object type annotation and dropdown buttons.
Project description
Local ToC – Sphinx extension
Sphinx Local Table of Contents Extension with Object Type Annotations and Dropdowns
This Sphinx extension enhances the local Table of Contents (ToC) by adding object type annotations (such as methods, attributes, and classes) and providing collapsible dropdowns for each object. It makes it easier for users to navigate complex documentation by categorizing and visualizing object types in a structured, interactive way.
Preview
|
|
Default configurationsThe image on the left shows the default configuration of this extension using the standard Furo dark theme. Object type annotations and dropdown controls are enabled, providing a compact and navigable local Table of Contents for API-heavy pages. |
|
|
CustomizedThe image on the left shows a customized configuration of this extension using the Furo dark theme. The title area shown above the Table of Contents is not managed by this extension.
All visual changes were made using CSS only, combined with the configuration option
|
Features
- Object Type Annotations: Automatically categorizes objects in the ToC like classes, methods, attributes, etc.
- Collapsible Dropdowns: Adds dropdown buttons next to each object type, allowing users to collapse or expand nested items.
- Customizable: Offers view configuration variables and CSS classes to control which future and how they are displayed.
Requirements
- Python • 3.12+
- Sphinx • 9.1.0+
- beautifulsoup4 • 4.14.3+
Installation
pip install sphinx-localtoc
Usage
Enable the extension
In your conf.py, add the extension to the extensions list.
Below is an example of a typical Sphinx configuration:
extensions = [
"sphinx.ext.autodoc", # pull in docstrings from code
"sphinx.ext.autosummary", # generate summary/API pages
"sphinx.ext.napoleon", # support Google/NumPy-style docstrings
"sphinx.ext.intersphinx", # link to external docs (Kivy, Python, etc.)
"sphinx.ext.todo", # support for exposing todo notes
"sphinx_localtoc", # stylizing the local TOC
]
Configuration options
The extension provides the following configuration variables, shown here with their default values:
# Enable or disable object type annotations in the local ToC.
localtoc_types = True
# Absolute or relative path (including filename) to a debug log file.
# If the file does not exist, it will be created.
# If it already exists, it will be overwritten.
localtoc_type_debug_file = ""
# Enable or disable the dropdown system in the local ToC.
localtoc_dropdown = True
# Number of initial ToC depth levels to skip before applying dropdown logic.
localtoc_dropdown_depth = 1
Debug file example
The debug file feature records all detected object types during the build process.
- This feature runs only during a full build, or when the
_builddirectory has been removed. - The file path is resolved relative to
conf.py. - If the file already exists, it will be overwritten.
# Example configuration
localtoc_type_debug_file = "_static/ref/debug_ltt.txt"
The contents of the generated file depend on your project structure, but should look similar to the following:
#//|>-----------------------------------------------------------------------------------------------------------------<|
#//| Debug Local ToC report for Sphinx extension
#//| Project: KivyDK
#//| Version: 0.1.0
#//|>-----------------------------------------------------------------------------------------------------------------<|
#//|>--------------------------------------------------------<|
#//| Used CSS classes: 6
#//|>--------------------------------------------------------<|
• slt-dropdown | <input> items used as checkbox for dropdown system
• slt-dropdown-branch | Starting depth branch for <ul> items
• slt-dropdown-depth | Nested depth branch for <ul> items
• slt-dropdown-icon | <label> items used for the arrows of dropdown system
• slt-dropdown-leaf | Last <li> items in the depth branch
• slt-type | Common class for all object type items
#//|>--------------------------------------------------------<|
#//| Used object type CSS classes: 7
#//|>--------------------------------------------------------<|
• slt-obj-attribute
• slt-obj-class
• slt-obj-data
• slt-obj-exception
• slt-obj-function
• slt-obj-method
• slt-obj-property
#//|>--------------------------------------------------------<|
#//| One domain used
#//|>--------------------------------------------------------<|
• py | Python script
#//|>--------------------------------------------------------<|
#//| Used object types: 7
#//|>--------------------------------------------------------<|
• py | attribute
• py | class
• py | data
• py | exception
• py | function
• py | method
• py | property
License
MIT License
Copyright (c) 2026 Afanase Ioan (ASI)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sphinx_localtoc-26.2.9.2.tar.gz.
File metadata
- Download URL: sphinx_localtoc-26.2.9.2.tar.gz
- Upload date:
- Size: 18.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2783d41f527f31bde4fbb9962b982d19b85469b520a5e7022321c89f2c3ee4d6
|
|
| MD5 |
25ad75ee919be9ce18d9270191718594
|
|
| BLAKE2b-256 |
3a948f8a2738b2576e0457eb7514b0b8cdb0c435792467ddbdbcedfb47eb6cd9
|
File details
Details for the file sphinx_localtoc-26.2.9.2-py3-none-any.whl.
File metadata
- Download URL: sphinx_localtoc-26.2.9.2-py3-none-any.whl
- Upload date:
- Size: 17.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
90b466591bdebb73c30ad914f7868a622a710dde1fb247a8a94e05257eaf7f87
|
|
| MD5 |
2ea5554cef056a180422bb63a2de5f0d
|
|
| BLAKE2b-256 |
f7fb9e4f897bfa04857acb1712f21888c8263c6724ed0a1fb94c13d28fd8350f
|