From fc2edd29a8899e752a70d01121e4079ecba2ff46 Mon Sep 17 00:00:00 2001 From: Jakob Lykke Andersen Date: Fri, 27 Mar 2020 16:41:08 +0100 Subject: [PATCH] Add ObjectDescription.transform_content() --- CHANGES | 2 ++ sphinx/directives/__init__.py | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/CHANGES b/CHANGES index f0c19c854..2be79fc03 100644 --- a/CHANGES +++ b/CHANGES @@ -13,6 +13,8 @@ Deprecated Features added -------------- +* Added ``ObjectDescription.transform_content()``. + Bugs fixed ---------- diff --git a/sphinx/directives/__init__.py b/sphinx/directives/__init__.py index 6b5df39b8..574962d81 100644 --- a/sphinx/directives/__init__.py +++ b/sphinx/directives/__init__.py @@ -126,6 +126,15 @@ class ObjectDescription(SphinxDirective): """ pass + def transform_content(self, contentnode: addnodes.desc_content) -> None: + """ + Called after creating the content through nested parsing, + but before the ``object-description-transform`` event is emitted, + and before the info-fields are transformed. + Can be used to manipulate the content. + """ + pass + def after_content(self) -> None: """ Called after parsing content. Used to reset information about the @@ -198,6 +207,7 @@ class ObjectDescription(SphinxDirective): self.env.temp_data['object'] = self.names[0] self.before_content() self.state.nested_parse(self.content, self.content_offset, contentnode) + self.transform_content(contentnode) self.env.app.emit('object-description-transform', self.domain, self.objtype, contentnode) DocFieldTransformer(self).transform_all(contentnode)