From 2c1afe0e163fd21cb4c4316ff6aa30a70a7b21d8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 6 Sep 2019 12:30:11 +0200 Subject: [PATCH] documentation/python: fire scope hooks for page rendering as well. 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 | 18 +++++++++--------- documentation/python.py | 8 ++++++++ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/doc/documentation/python.rst b/doc/documentation/python.rst index 50071d8b..7fbe9d3b 100644 --- a/doc/documentation/python.rst +++ b/doc/documentation/python.rst @@ -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 diff --git a/documentation/python.py b/documentation/python.py index fe77bb95..69b29773 100755 --- a/documentation/python.py +++ b/documentation/python.py @@ -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): -- 2.30.2