chiark / gitweb /
documentation/python: fire scope hooks for page rendering as well.
authorVladimír Vondruš <mosra@centrum.cz>
Fri, 6 Sep 2019 10:30:11 +0000 (12:30 +0200)
committerVladimír Vondruš <mosra@centrum.cz>
Fri, 6 Sep 2019 10:30:11 +0000 (12:30 +0200)
Right now this will be used to implement a page-specific :ref-prefix:
option, but in the future it can be used also for relative linking to
pages and such.

doc/documentation/python.rst
documentation/python.py

index 50071d8b70a7f1964cd049fe8bd8815dce23a2d0..7fbe9d3b112716a736d83c8dae74cdae5ef62dbf 100644 (file)
@@ -933,15 +933,15 @@ Keyword argument    Content
     script as well as other plugins can correctly distinguish them.
 
 The :py:`hooks_pre_scope` and :py:`hooks_post_scope` get called before entering
-and after leaving a name scope, and are meant mainly to aid with
-context-sensitive linking. Those scopes can be nested and can be called
-successively for the same scope --- for example, when rendering module docs,
-:py:`hooks_pre_scope` gets called first for the module scope, but then another
-:py:`hooks_pre_scope` gets called when rendering a summary for reference to an
-inner class. Then, :py:`hooks_post_scope` gets called in reverse order. The
-plugins are expected to implement a stack-like data structure for maintaining
-information about current scope. Both of those functions get passed the
-following arguments:
+and after leaving a name scope (page, module, class, enum, enum value,
+function, property or data), and are meant mainly to aid with context-sensitive
+linking. Those scopes can be nested and can be called successively for the same
+scope --- for example, when rendering module docs, :py:`hooks_pre_scope` gets
+called first for the module scope, but then another :py:`hooks_pre_scope` gets
+called when rendering a summary for reference to an inner class. Then,
+:py:`hooks_post_scope` gets called in reverse order. The plugins are expected
+to implement a stack-like data structure for maintaining information about
+current scope. Both of those functions get passed the following arguments:
 
 .. class:: m-table
 
index fe77bb959d5443fc7dc4b1a0783de80f12bcd3d9..69b297738bc6d113158ae983b3a408c938eef181 100755 (executable)
@@ -2149,6 +2149,10 @@ def render_page(state: State, path, input_filename, env):
     page.url = url
     page.prefix_wbr = path[0]
 
+    # Call all scope enter hooks before
+    for hook in state.hooks_pre_scope:
+        hook(type=EntryType.PAGE, path=path)
+
     # Render the file
     with open(input_filename, 'r') as f:
         try:
@@ -2171,6 +2175,10 @@ def render_page(state: State, path, input_filename, env):
                 page=page)
             return
 
+    # Call all scope exit hooks last
+    for hook in state.hooks_post_scope:
+        hook(type=EntryType.PAGE, path=path)
+
     # Extract metadata from the page
     metadata = {}
     for docinfo in pub.document.traverse(docutils.nodes.docinfo):