File tree Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ def setup(app: "Sphinx") -> dict:
1313 """Initialize the Sphinx extension."""
1414 from .events import (
1515 add_changed_toctrees ,
16- insert_toctrees ,
16+ InsertToctrees ,
1717 parse_toc_to_env ,
1818 TableofContents ,
1919 )
@@ -28,7 +28,6 @@ def setup(app: "Sphinx") -> dict:
2828 app .connect ("config-inited" , parse_toc_to_env , priority = 900 )
2929 app .connect ("env-get-outdated" , add_changed_toctrees )
3030 app .add_directive ("tableofcontents" , TableofContents )
31- # Note: this needs to occur before `TocTreeCollector.process_doc` (default priority 500)
32- app .connect ("doctree-read" , insert_toctrees , priority = 100 )
31+ app .add_transform (InsertToctrees )
3332
3433 return {"version" : __version__ , "parallel_read_safe" : True }
Original file line number Diff line number Diff line change 99from sphinx .config import Config
1010from sphinx .environment import BuildEnvironment
1111from sphinx .errors import ExtensionError
12+ from sphinx .transforms import SphinxTransform
1213from sphinx .util import docname_join , logging
1314from sphinx .util .docutils import SphinxDirective
1415from sphinx .util .matching import Matcher , patfilter , patmatch
@@ -262,3 +263,16 @@ def insert_toctrees(app: Sphinx, doctree: nodes.document) -> None:
262263 # since `TocTreeCollector.process_doc` expects it in a section
263264 # TODO check if there is this is always ok
264265 doctree .children [- 1 ].extend (node_list )
266+
267+
268+ class InsertToctrees (SphinxTransform ):
269+ """Create the toctree nodes and add it to the document.
270+
271+ This needs to occur at least before the ``DoctreeReadEvent`` (priority 880),
272+ which triggers the `TocTreeCollector.process_doc` event (priority 500)
273+ """
274+
275+ default_priority = 100
276+
277+ def apply (self , ** kwargs : Any ) -> None :
278+ insert_toctrees (self .app , self .document )
You can’t perform that action at this time.
0 commit comments