pax_global_header 0000666 0000000 0000000 00000000064 14536031355 0014517 g ustar 00root root 0000000 0000000 52 comment=172e0e7ed0bd503ad80208582f0d58ede662baab
sphinx-external-toc-1.0.1/ 0000775 0000000 0000000 00000000000 14536031355 0015432 5 ustar 00root root 0000000 0000000 sphinx-external-toc-1.0.1/.github/ 0000775 0000000 0000000 00000000000 14536031355 0016772 5 ustar 00root root 0000000 0000000 sphinx-external-toc-1.0.1/.github/dependabot.yml 0000664 0000000 0000000 00000000243 14536031355 0021621 0 ustar 00root root 0000000 0000000 version: 2
updates:
# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
sphinx-external-toc-1.0.1/.github/workflows/ 0000775 0000000 0000000 00000000000 14536031355 0021027 5 ustar 00root root 0000000 0000000 sphinx-external-toc-1.0.1/.github/workflows/tests.yml 0000664 0000000 0000000 00000003466 14536031355 0022725 0 ustar 00root root 0000000 0000000 # This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
name: continuous-integration
on:
push:
branches: [main]
tags:
- "v[0-9]+.[0-9]+.[0-9]+*"
pull_request:
jobs:
tests:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: ["3.9", "3.10", "3.11", "3.12"]
include:
- os: windows-latest
python-version: 3.9
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .[testing]
- name: Run pytest
run: |
pytest --cov=sphinx_external_toc --cov-report=xml --cov-report=term-missing
- name: Upload to Codecov
if: matrix.python-version == 3.11
uses: codecov/codecov-action@v3
with:
name: pytests-py3.11
flags: pytests
file: ./coverage.xml
fail_ci_if_error: true
publish:
name: Publish to PyPI
needs: [tests]
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.11
- name: install flit
run: |
pip install flit~=3.4
- name: Build and publish
run: |
flit publish
env:
FLIT_USERNAME: __token__
FLIT_PASSWORD: ${{ secrets.PYPI_KEY }}
sphinx-external-toc-1.0.1/.gitignore 0000664 0000000 0000000 00000003425 14536031355 0017426 0 ustar 00root root 0000000 0000000 # Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
.python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
.vscode/
~$*
sphinx-external-toc-1.0.1/.pre-commit-config.yaml 0000664 0000000 0000000 00000001126 14536031355 0021713 0 ustar 00root root 0000000 0000000 # Install pre-commit hooks via
# pre-commit install
exclude: >
(?x)^(
\.vscode/settings\.json|
tests/.*xml|
tests/.*txt|
)$
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-json
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.4
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
- id: ruff-format
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.6.1
hooks:
- id: mypy
sphinx-external-toc-1.0.1/.readthedocs.yml 0000664 0000000 0000000 00000000327 14536031355 0020522 0 ustar 00root root 0000000 0000000 version: 2
build:
os: ubuntu-22.04
tools:
python: "3.11"
python:
install:
- method: pip
path: .
extra_requirements:
- rtd
sphinx:
builder: html
fail_on_warning: true
sphinx-external-toc-1.0.1/CHANGELOG.md 0000664 0000000 0000000 00000017303 14536031355 0017247 0 ustar 00root root 0000000 0000000 # Change Log
## v1.0.1 - 2023-12-12
([full changelog](https://github.com/executablebooks/sphinx-external-toc/compare/v1.0.0...21adcf94ca0e09e7fbce21bf87734435520169f2))
### Bugs fixed
- FIX: rework 104 to support e.g. PDFHTML [#105](https://github.com/executablebooks/sphinx-external-toc/pull/105) ([@agoose77](https://github.com/agoose77))
- FIX: exit if non-html builder [#104](https://github.com/executablebooks/sphinx-external-toc/pull/104) ([@agoose77](https://github.com/agoose77))
- FIX: simple grammatical error in `index.md` [#100](https://github.com/executablebooks/sphinx-external-toc/pull/100) ([@kallewesterling](https://github.com/kallewesterling))
### Maintenance and upkeep improvements
- MAINT: update changelog via github-activity [#102](https://github.com/executablebooks/sphinx-external-toc/pull/102) ([@agoose77](https://github.com/agoose77))
### Other merged PRs
- Bump actions/setup-python from 4 to 5 [#103](https://github.com/executablebooks/sphinx-external-toc/pull/103) ([@dependabot](https://github.com/dependabot))
### Contributors to this release
([GitHub contributors page for this release](https://github.com/executablebooks/sphinx-external-toc/graphs/contributors?from=2023-11-08&to=2023-12-12&type=c))
[@agoose77](https://github.com/search?q=repo%3Aexecutablebooks%2Fsphinx-external-toc+involves%3Aagoose77+updated%3A2023-11-08..2023-12-12&type=Issues) | [@codecov](https://github.com/search?q=repo%3Aexecutablebooks%2Fsphinx-external-toc+involves%3Acodecov+updated%3A2023-11-08..2023-12-12&type=Issues) | [@dependabot](https://github.com/search?q=repo%3Aexecutablebooks%2Fsphinx-external-toc+involves%3Adependabot+updated%3A2023-11-08..2023-12-12&type=Issues) | [@kallewesterling](https://github.com/search?q=repo%3Aexecutablebooks%2Fsphinx-external-toc+involves%3Akallewesterling+updated%3A2023-11-08..2023-12-12&type=Issues) | [@welcome](https://github.com/search?q=repo%3Aexecutablebooks%2Fsphinx-external-toc+involves%3Awelcome+updated%3A2023-11-08..2023-12-12&type=Issues)
## 1.0.0 - 2023-11-08
([full changelog](https://github.com/executablebooks/sphinx-external-toc/compare/v0.3.1...9e8cc1f92d84fed6eb9602371709b6a88e47f688))
### Merged PRs
- maint: add ruff [#101](https://github.com/executablebooks/sphinx-external-toc/pull/101) ([@agoose77](https://github.com/agoose77))
- Bump actions/checkout from 3 to 4 [#98](https://github.com/executablebooks/sphinx-external-toc/pull/98) ([@dependabot](https://github.com/dependabot))
- chore: update versioning [#97](https://github.com/executablebooks/sphinx-external-toc/pull/97) ([@agoose77](https://github.com/agoose77))
- fixes https://github.com/executablebooks/jupyter-book/issues/1414 [#94](https://github.com/executablebooks/sphinx-external-toc/pull/94) ([@jdsalaro](https://github.com/jdsalaro))
- [pre-commit.ci] pre-commit autoupdate [#82](https://github.com/executablebooks/sphinx-external-toc/pull/82) ([@pre-commit-ci](https://github.com/pre-commit-ci))
### Contributors to this release
([GitHub contributors page for this release](https://github.com/executablebooks/sphinx-external-toc/graphs/contributors?from=2022-11-24&to=2023-12-04&type=c))
[@agoose77](https://github.com/search?q=repo%3Aexecutablebooks%2Fsphinx-external-toc+involves%3Aagoose77+updated%3A2022-11-24..2023-12-04&type=Issues) | [@codecov](https://github.com/search?q=repo%3Aexecutablebooks%2Fsphinx-external-toc+involves%3Acodecov+updated%3A2022-11-24..2023-12-04&type=Issues) | [@dependabot](https://github.com/search?q=repo%3Aexecutablebooks%2Fsphinx-external-toc+involves%3Adependabot+updated%3A2022-11-24..2023-12-04&type=Issues) | [@jdsalaro](https://github.com/search?q=repo%3Aexecutablebooks%2Fsphinx-external-toc+involves%3Ajdsalaro+updated%3A2022-11-24..2023-12-04&type=Issues) | [@mmcky](https://github.com/search?q=repo%3Aexecutablebooks%2Fsphinx-external-toc+involves%3Ammcky+updated%3A2022-11-24..2023-12-04&type=Issues) | [@pre-commit-ci](https://github.com/search?q=repo%3Aexecutablebooks%2Fsphinx-external-toc+involves%3Apre-commit-ci+updated%3A2022-11-24..2023-12-04&type=Issues) | [@welcome](https://github.com/search?q=repo%3Aexecutablebooks%2Fsphinx-external-toc+involves%3Awelcome+updated%3A2022-11-24..2023-12-04&type=Issues)
## 0.3.1 - 2022-11-25
- ⬆️ UPGRADE: Support `sphinx5` [#85](https://github.com/executablebooks/sphinx-external-toc/pull/85)
## 0.3.0 - 2022-04-16
- ⬆️ UPGRADE: Drop python 3.6 support (#75)
- ♻️ REFACTOR: Replace `attrs` with built-in `dataclasses` (#76)
- 🐛 FIX: gettext builder compatibility
- 🐛 FIX: Inserting toctree into empty document (#77)
- 🔧 MAINTAIN: Move from setuptools to flit, for PEP 621 packaging (#74)
## 0.2.4 - 2022-02-10
### What's Changed
- ⬆️ UPGRADE: allow click v8 by @lukasbindreiter in https://github.com/executablebooks/sphinx-external-toc/pull/69
- 📚: Fix ToC graphic link by @ZviBaratz in https://github.com/executablebooks/sphinx-external-toc/pull/63
- 🔧 MAINTAIN: Updated parser docstrings by @ZviBaratz in https://github.com/executablebooks/sphinx-external-toc/pull/61
- 🔧 MAINTAIN: Removed unused argument by @ZviBaratz in https://github.com/executablebooks/sphinx-external-toc/pull/66
- 🔧 MAINTAIN: Updated `api` docstrings by @ZviBaratz in https://github.com/executablebooks/sphinx-external-toc/pull/64
- 🔧: Docstring updates by @ZviBaratz in https://github.com/executablebooks/sphinx-external-toc/pull/67
### New Contributors
- @ZviBaratz made their first contribution in https://github.com/executablebooks/sphinx-external-toc/pull/61
- @lukasbindreiter made their first contribution in https://github.com/executablebooks/sphinx-external-toc/pull/69
**Full Changelog**: https://github.com/executablebooks/sphinx-external-toc/compare/v0.2.3...v0.2.4
## 0.2.3 - 2021-07-29
🔧 MAINTAIN: Update `attrs` minimum version to `20.3`, when `value_serializer` was introduced (required here).
👌 IMPROVE: Changed document identification.
The comparison of sitemaps and identification of changed documents to rebuild was improved and moved to `SiteMap.get_changed`.
## 0.2.2 - 2021-06-25
🐛 FIX: File extensions in ToC
Ensure files are still matched, if they are provided with file extensions.
## 0.2.1 - 2021-06-16
- ⬆️ UPDATE: Relax dependency pinning to allow Sphinx v4
## 0.2.0 - 2021-05-24
- ‼ BREAKING: the CLI command `to-site` is now `to-project`, and `from-site` is now `from-project`
## 0.1.0 - 2021-04-27
- ♻️ REFACTOR: key `items` -> `entries`
- 👌 IMPROVE: Add `--output` to `migrate` command
## 0.1.0a8 - 2021-04-19
- 👌 IMPROVE: validate URL: Ensure value of `url` keys match regex used by Sphinx to identify them
- 🐛 FIX: `external_toc_path` with absolute path
## 0.1.0a7 - 2021-04-18
- 👌 IMPROVE: Parsing `MalformedError` messages
- 👌 IMPROVE: jupyter-book migration
- Better conversion validation
- Move `options` key above `parts`/`chapters`/`sections` key
## 0.1.0a6 - 2021-04-18
- 👌 IMPROVE: Add `ensure_index_file` event on build completion
- ♻️ REFACTOR: Rename key: `parts` -> `subtrees`
- ♻️ REFACTOR: `sections` -> `items`, and add `format`
- The `format` key adds key-mapping for jupyter-book support.
- ♻️ REFACTOR: API naming: renamed to be more general:
- `DocItem` -> `Document`
- `DocItem.parts` -> `Document.subtrees`
- `TocItem` -> `TocTree`
- `TocItem.sections` -> `TocTree.items`
## 0.1.0a5 - 2021-04-10
🐛 FIX: `numbered: true`, this was being equated to `numbered: 1` rather than `numbered: 999` (i.e. infinite depth).
## 0.1.0a4 - 2021-04-10
- ♻️ REFACTOR: Move parsing code to separate module
- ✨ NEW: Improve option parsing, add jupyter-book migration
## 0.1.0a3 - 2021-04-09
👌 IMPROVE: `toc.yml` validation
## 0.1.0a2 - 2021-04-08
🐛 FIX: for nested docnames in sub-folders
## 0.1.0a1 - 2021-04-08
Initial alpha release.
sphinx-external-toc-1.0.1/CONTRIBUTING.md 0000664 0000000 0000000 00000001160 14536031355 0017661 0 ustar 00root root 0000000 0000000 # Contributing
`sphinx-external-toc` is part of the executablebooks project, who also are responsible for `jupyter-book`.
We're excited you're here and want to contribute.
The Jupyter Book project is run by a community of people like you, we'd love to have you
help out!
Please take a look at the [Jupyter Book contributor guide](https://jupyterbook.org/en/stable/contribute/intro.html)
which steps you through the codebase and how to contribute to this project.
If you have any questions that aren't answered there, please let us know by
[opening an issue][link_issues]!
Thank you for you interest in contributing ✨
sphinx-external-toc-1.0.1/LICENSE 0000664 0000000 0000000 00000002061 14536031355 0016436 0 ustar 00root root 0000000 0000000 MIT License
Copyright (c) 2021 Executable Books
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.
sphinx-external-toc-1.0.1/README.md 0000664 0000000 0000000 00000033667 14536031355 0016730 0 ustar 00root root 0000000 0000000 # sphinx-external-toc
[![Github-CI][github-ci]][github-link]
[![Coverage Status][codecov-badge]][codecov-link]
[![Code style: black][black-badge]][black-link]
[![PyPI][pypi-badge]][pypi-link]
A sphinx extension that allows the documentation site-map (a.k.a Table of Contents) to be defined external to the documentation files.
As used by [Jupyter Book](https://jupyterbook.org)!
In normal Sphinx documentation, the documentation site-map is defined *via* a bottom-up approach - adding [`toctree` directives](https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#table-of-contents) within pages of the documentation.
This extension facilitates a **top-down** approach to defining the site-map structure, within a single YAML file.

It also allows for documents not specified in the ToC to be auto-excluded.
## User Guide
### Sphinx Configuration
Add to your `conf.py`:
```python
extensions = ["sphinx_external_toc"]
external_toc_path = "_toc.yml" # optional, default: _toc.yml
external_toc_exclude_missing = False # optional, default: False
```
Note the `external_toc_path` is always read as a Unix path, and can either be specified relative to the source directory (recommended) or as an absolute path.
### Basic Structure
A minimal ToC defines the top level `root` key, for a single root document file:
```yaml
root: intro
```
The value of the `root` key will be a path to a file, in Unix format (folders split by `/`), relative to the source directory, and can be with or without the file extension.
:::{note}
This root file will be set as the [`master_doc`](https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-master_doc).
:::
Document files can then have a `subtrees` key - denoting a list of individual toctrees for that document - and in-turn each subtree should have a `entries` key - denoting a list of children links, that are one of:
- `file`: path to a single document file in Unix format, with or without the file extension (as for `root`)
- `glob`: path to one or more document files *via* Unix shell-style wildcards (similar to [`fnmatch`](https://docs.python.org/3/library/fnmatch.html), but single stars don't match slashes.)
- `url`: path for an external URL (starting e.g. `http` or `https`)
:::{important}
Each document file can only occur once in the ToC!
:::
This can proceed recursively to any depth.
```yaml
root: intro
subtrees:
- entries:
- file: doc1
subtrees:
- entries:
- file: doc2
subtrees:
- entries:
- file: doc3
- url: https://example.com
- glob: subfolder/other*
```
This is equivalent to having a single `toctree` directive in `intro`, containing `doc1`,
and a single `toctree` directive in `doc1`, with the `:glob:` flag and containing `doc2`, `https://example.com` and `subfolder/other*`.
As a shorthand, the `entries` key can be at the same level as the `file`, which denotes a document with a single subtree.
For example, this file is exactly equivalent to the one above:
```yaml
root: intro
entries:
- file: doc1
entries:
- file: doc2
entries:
- file: doc3
- url: https://example.com
- glob: subfolder/other*
```
### File and URL titles
By default, the initial header within a `file` document will be used as its title in generated Table of Contents.
With the `title` key you can set an alternative title for a document. and also for `url`:
```yaml
root: intro
subtrees:
- entries:
- file: doc1
title: Document 1 Title
- url: https://example.com
title: Example URL Title
```
### ToC tree options
Each subtree can be configured with a number of options (see also [sphinx `toctree` options](https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#directive-toctree)):
- `caption` (string): A title for the whole the subtree, e.g. shown above the subtree in ToCs
- `hidden` (boolean): Whether to show the ToC within (inline of) the document (default `False`).
By default it is appended to the end of the document, but see also the `tableofcontents` directive for positioning of the ToC.
- `maxdepth` (integer): A maximum nesting depth to use when showing the ToC within the document (default -1, meaning infinite).
- `numbered` (boolean or integer): Automatically add numbers to all documents within a subtree (default `False`).
If set to `True`, all sub-trees will also be numbered based on nesting (e.g. with `1.1` or `1.1.1`),
or if set to an integer then the numbering will only be applied to that depth.
- `reversed` (boolean): If `True` then the entries in the subtree will be listed in reverse order (default `False`).
This can be useful when using `glob` entries.
- `titlesonly` (boolean): If `True` then only the first heading in the document will be shown in the ToC, not other headings of the same level (default `False`).
These options can be set at the level of the subtree:
```yaml
root: intro
subtrees:
- caption: Subtree Caption
hidden: False
maxdepth: 1
numbered: True
reversed: False
titlesonly: True
entries:
- file: doc1
subtrees:
- titlesonly: True
entries:
- file: doc2
```
or, if you are using the shorthand for a single subtree, set options under an `options` key:
```yaml
root: intro
options:
caption: Subtree Caption
hidden: False
maxdepth: 1
numbered: True
reversed: False
titlesonly: True
entries:
- file: doc1
options:
titlesonly: True
entries:
- file: doc2
```
You can also use the top-level `defaults` key, to set default options for all subtrees:
```yaml
root: intro
defaults:
titlesonly: True
options:
caption: Subtree Caption
hidden: False
maxdepth: 1
numbered: True
reversed: False
entries:
- file: doc1
entries:
- file: doc2
```
:::{warning}
`numbered` should not generally be used as a default, since numbering cannot be changed by nested subtrees, and sphinx will log a warning.
:::
:::{note}
By default, title numbering restarts for each subtree.
If you want want this numbering to be continuous, check-out the [sphinx-multitoc-numbering extension](https://github.com/executablebooks/sphinx-multitoc-numbering).
:::
### Using different key-mappings
For certain use-cases, it is helpful to map the `subtrees`/`entries` keys to mirror e.g. an output [LaTeX structure](https://www.overleaf.com/learn/latex/sections_and_chapters).
The `format` key can be used to provide such mappings (and also initial defaults).
Currently available:
- `jb-article`:
- Maps `entries` -> `sections`
- Sets the default of `titlesonly` to `true`
- `jb-book`:
- Maps the top-level `subtrees` to `parts`
- Maps the top-level `entries` to `chapters`
- Maps other levels of `entries` to `sections`
- Sets the default of `titlesonly` to `true`
For example:
```yaml
defaults:
titlesonly: true
root: index
subtrees:
- entries:
- file: doc1
entries:
- file: doc2
```
is equivalent to:
```yaml
format: jb-book
root: index
parts:
- chapters:
- file: doc1
sections:
- file: doc2
```
:::{important}
These change in key names do not change the output site-map structure.
:::
## Add a ToC to a page's content
By default, the `toctree` generated per document (one per subtree) are appended to the end of the document and hidden (then, for example, most HTML themes show them in a side-bar).
But if you would like them to be visible at a certain place within the document body, you may do so by using the `tableofcontents` directive:
ReStructuredText:
```restructuredtext
.. tableofcontents::
```
MyST Markdown:
````md
```{tableofcontents}
```
````
Currently, only one `tableofcontents` should be used per page (all `toctree` will be added here), and only if it is a page with child/descendant documents.
Note, this will override the `hidden` option set for a subtree.
## Excluding files not in ToC
By default, Sphinx will build all document files, regardless of whether they are specified in the Table of Contents, if they:
1. Have a file extension relating to a loaded parser (e.g. `.rst` or `.md`)
2. Do not match a pattern in [`exclude_patterns`](https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-exclude_patterns)
To automatically add any document files that do not match a `file` or `glob` in the ToC to the `exclude_patterns` list, add to your `conf.py`:
```python
external_toc_exclude_missing = True
```
Note that, for performance, files that are in *hidden folders* (e.g. in `.tox` or `.venv`) will not be added to `exclude_patterns` even if they are not specified in the ToC.
You should exclude these folders explicitly.
:::{important}
This feature is not currently compatible with [orphan files](https://www.sphinx-doc.org/en/master/usage/restructuredtext/field-lists.html#metadata).
:::
## Command-line
This package comes with the `sphinx-etoc` command-line program, with some additional tools.
To see all options:
```console
$ sphinx-etoc --help
Usage: sphinx-etoc [OPTIONS] COMMAND [ARGS]...
Command-line for sphinx-external-toc.
Options:
--version Show the version and exit.
-h, --help Show this message and exit.
Commands:
from-project Create a ToC file from a project directory.
migrate Migrate a ToC from a previous revision.
parse Parse a ToC file to a site-map YAML.
to-project Create a project directory from a ToC file.
```
To build a template project from only a ToC file:
```console
$ sphinx-etoc to-project -p path/to/site -e rst path/to/_toc.yml
```
Note, you can also add additional files in `meta`/`create_files` amd append text to the end of files with `meta`/`create_append`, e.g.
```yaml
root: intro
entries:
- glob: doc*
meta:
create_append:
intro: |
This is some
appended text
create_files:
- doc1
- doc2
- doc3
```
To build a ToC file from an existing site:
```console
$ sphinx-etoc from-project path/to/folder
```
Some rules used:
- Files/folders will be skipped if they match a pattern added by `-s` (based on [fnmatch](https://docs.python.org/3/library/fnmatch.html) Unix shell-style wildcards)
- Sub-folders with no content files inside will be skipped
- File and folder names will be sorted by [natural order](https://en.wikipedia.org/wiki/Natural_sort_order)
- If there is a file called `index` (or the name set by `-i`) in any folder, it will be treated as the index file, otherwise the first file by ordering will be used.
The command can also guess a `title` for each file, based on its path:
- The folder name is used for index files, otherwise the file name
- Words are split by `_`
- The first "word" is removed if it is an integer
For example, for a project with files:
```
index.rst
1_a_title.rst
11_another_title.rst
.hidden_file.rst
.hidden_folder/index.rst
1_a_subfolder/index.rst
2_another_subfolder/index.rst
2_another_subfolder/other.rst
3_subfolder/1_no_index.rst
3_subfolder/2_no_index.rst
14_subfolder/index.rst
14_subfolder/subsubfolder/index.rst
14_subfolder/subsubfolder/other.rst
```
will create the ToC:
```console
$ sphinx-etoc from-project path/to/folder -i index -s ".*" -e ".rst" -t
root: index
entries:
- file: 1_a_title
title: A title
- file: 11_another_title
title: Another title
- file: 1_a_subfolder/index
title: A subfolder
- file: 2_another_subfolder/index
title: Another subfolder
entries:
- file: 2_another_subfolder/other
title: Other
- file: 3_subfolder/1_no_index
title: No index
entries:
- file: 3_subfolder/2_no_index
title: No index
- file: 14_subfolder/index
title: Subfolder
entries:
- file: 14_subfolder/subsubfolder/index
title: Subsubfolder
entries:
- file: 14_subfolder/subsubfolder/other
title: Other
```
## API
The ToC file is parsed to a `SiteMap`, which is a `MutableMapping` subclass, with keys representing docnames mapping to a `Document` that stores information on the toctrees it should contain:
```python
import yaml
from sphinx_external_toc.parsing import parse_toc_yaml
path = "path/to/_toc.yml"
site_map = parse_toc_yaml(path)
yaml.dump(site_map.as_json())
```
Would produce e.g.
```yaml
root: intro
documents:
doc1:
docname: doc1
subtrees: []
title: null
intro:
docname: intro
subtrees:
- caption: Subtree Caption
numbered: true
reversed: false
items:
- doc1
titlesonly: true
title: null
meta: {}
```
## Development Notes
Questions / TODOs:
- Add additional top-level keys, e.g. `appendices` (see https://github.com/sphinx-doc/sphinx/issues/2502) and `bibliography`
- Using `external_toc_exclude_missing` to exclude a certain file suffix:
currently if you had files `doc.md` and `doc.rst`, and put `doc.md` in your ToC,
it will add `doc.rst` to the excluded patterns but then, when looking for `doc.md`,
will still select `doc.rst` (since it is first in `source_suffix`).
Maybe open an issue on sphinx, that `doc2path` should respect exclude patterns.
- Integrate https://github.com/executablebooks/sphinx-multitoc-numbering into this extension? (or upstream PR)
- document suppressing warnings
- test against orphan file
- https://github.com/executablebooks/sphinx-book-theme/pull/304
- CLI command to generate toc from existing documentation `toctrees` (and then remove toctree directives)
- test rebuild on toc changes (and document how rebuilds are controlled when toc changes)
- some jupyter-book issues point to potential changes in numbering, based on where the `toctree` is in the document.
So could look into placing it e.g. under the first heading/title
[github-ci]: https://github.com/executablebooks/sphinx-external-toc/workflows/continuous-integration/badge.svg?branch=main
[github-link]: https://github.com/executablebooks/sphinx-external-toc
[codecov-badge]: https://codecov.io/gh/executablebooks/sphinx-external-toc/branch/main/graph/badge.svg
[codecov-link]: https://codecov.io/gh/executablebooks/sphinx-external-toc
[black-badge]: https://img.shields.io/badge/code%20style-black-000000.svg
[black-link]: https://github.com/ambv/black
[pypi-badge]: https://img.shields.io/pypi/v/sphinx-external-toc.svg
[pypi-link]: https://pypi.org/project/sphinx-external-toc
sphinx-external-toc-1.0.1/codecov.yml 0000664 0000000 0000000 00000000242 14536031355 0017575 0 ustar 00root root 0000000 0000000 coverage:
status:
project:
default:
target: 90%
threshold: 0.2%
patch:
default:
target: 75%
threshold: 0.2%
sphinx-external-toc-1.0.1/docs/ 0000775 0000000 0000000 00000000000 14536031355 0016362 5 ustar 00root root 0000000 0000000 sphinx-external-toc-1.0.1/docs/_toc.yml 0000664 0000000 0000000 00000000626 14536031355 0020035 0 ustar 00root root 0000000 0000000 root: intro
subtrees:
- caption: User Guide
numbered: true
entries:
- file: user_guide/sphinx
- file: user_guide/cli
- file: user_guide/api
- caption: Example
entries:
- file: example/index
entries:
- file: example/subfolder/page
- glob: example/globfolder/*
- caption: Links
entries:
- title: GitHub Repository
url: https://github.com/executablebooks/sphinx-external-toc
sphinx-external-toc-1.0.1/docs/conf.py 0000664 0000000 0000000 00000001226 14536031355 0017662 0 ustar 00root root 0000000 0000000 """Configuration file for the Sphinx documentation builder."""
project = "Sphinx External ToC"
copyright = "2021, Executable Book Project"
author = "Executable Book Project"
extensions = ["myst_parser", "sphinx_external_toc"]
myst_enable_extensions = ["colon_fence", "html_image"]
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
external_toc_exclude_missing = True
html_theme = "sphinx_book_theme"
html_title = project
html_theme_options = {
"home_page_in_toc": True,
"use_edit_page_button": True,
"repository_url": "https://github.com/executablebooks/sphinx-external-toc",
"repository_branch": "main",
"path_to_docs": "docs",
}
sphinx-external-toc-1.0.1/docs/example/ 0000775 0000000 0000000 00000000000 14536031355 0020015 5 ustar 00root root 0000000 0000000 sphinx-external-toc-1.0.1/docs/example/globfolder/ 0000775 0000000 0000000 00000000000 14536031355 0022134 5 ustar 00root root 0000000 0000000 sphinx-external-toc-1.0.1/docs/example/globfolder/page1.md 0000664 0000000 0000000 00000000066 14536031355 0023455 0 ustar 00root root 0000000 0000000 # Sub-section Glob Page 1
A page added via globbing.
sphinx-external-toc-1.0.1/docs/example/globfolder/page2.md 0000664 0000000 0000000 00000000074 14536031355 0023455 0 ustar 00root root 0000000 0000000 # Sub-section Glob Page 2
Another page added via globbing.
sphinx-external-toc-1.0.1/docs/example/index.md 0000664 0000000 0000000 00000000211 14536031355 0021440 0 ustar 00root root 0000000 0000000 # Example Project
These pages provide an example of different aspects of the ToC.
See this project's `_toc.yml` for how they are added.
sphinx-external-toc-1.0.1/docs/example/subfolder/ 0000775 0000000 0000000 00000000000 14536031355 0022002 5 ustar 00root root 0000000 0000000 sphinx-external-toc-1.0.1/docs/example/subfolder/page.md 0000664 0000000 0000000 00000000064 14536031355 0023240 0 ustar 00root root 0000000 0000000 # Sub-section Page
This is a page of a subsection.
sphinx-external-toc-1.0.1/docs/intro.md 0000664 0000000 0000000 00000001416 14536031355 0020041 0 ustar 00root root 0000000 0000000 # sphinx-external-toc
A sphinx extension that allows the documentation site-map (a.k.a Table of Contents) to be defined external to the documentation files.
As used by [Jupyter Book](https://jupyterbook.org)!
In normal Sphinx documentation, the documentation site-map is defined *via* a bottom-up approach - adding [`toctree` directives](https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#table-of-contents) within pages of the documentation.
This extension facilitates a **top-down** approach to defining the site-map structure, within a single YAML file.
:::{figure-md}
Example ToC
:::
It also allows for documents not specified in the ToC to be auto-excluded.
```{tableofcontents}
```
sphinx-external-toc-1.0.1/docs/toc-graphic.png 0000664 0000000 0000000 00000437576 14536031355 0021316 0 ustar 00root root 0000000 0000000 PNG
IHDR d sRGB xeXIfMM * > F( i N pHYs gR @ IDATx E3{"$W/!! 7(*`H6DW|((>AH (}_as3{L5=3;3;;33-OMu 2ziieD;ه _X=/Tn#}C E4UwׯK @3^rB@ t\''wo# FPYA% @*{NO[oYj hcO@ CXg@ ;켸@ KOֵvtkb~F t{"u)e*ﻷdmmOF μHt @ \%P/v@BG @ q,Q5WwfQ>u@ rQ;tu
e/v杻>˘@ @ Iu#Ϲ@ @ BA:5RfU.RE@ !ڪݡdT4VJSChC@ @ @ `@ @ q}KD(Hwؤ2t#~E 䋀Rq%JIB|>D @ @ #2I@ @ "oyi(y&$= Y=Nt(2 D@]Ji@ @ TSe:|iHF@pPIr2Q@ @ P75@ @ FN`>5Fpf@@LA N@],i @ @ zi
@`zV~?,5~lG @ @ P `МQQ z{>BUw# 3rR2@ @ @ 'PSʬNYh@ @ P_כ" D@K.@ @ @ @ @ @ /uu- KԹB
@ @ @ @ @ @ P_כ" D@K.@ @ @ @ @ @ /uu- KԹB
@ @ @ @ @ @ P_כ" D@K.@ @ @ @ @ @ /uu- KԹB
@ @ @ @ @ @ P_כ" D@K.@ @ @ @ @ @ /o~
" @&H{ߊf}OcE x UH9Iget7Z)b^[_K @ @ @ @ @`K~Q\ɕI `F @k,