From 62bd41dfdb8412c1fd7a5cc48ffd8a47414b86f2 Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Mon, 1 May 2023 15:39:45 -0700 Subject: [PATCH] remove unnecessary permalink to `depart_term()` (#252) * use rst-example in additional_samples.rst for glossary directive * conditionally add permalink for non-default behavior --- docs/additional_samples.rst | 20 +++++++++++--------- sphinx_immaterial/apidoc/object_toc.py | 8 +++++++- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/docs/additional_samples.rst b/docs/additional_samples.rst index 1f146d7ee..8c5e00ebf 100644 --- a/docs/additional_samples.rst +++ b/docs/additional_samples.rst @@ -190,17 +190,19 @@ Alignment Glossaries ========== -.. glossary:: +.. rst-example:: + + .. glossary:: - environment - A structure where information about all documents under the root is - saved, and used for cross-referencing. The environment is pickled - after the parsing stage, so that successive runs only need to read - and parse new and changed documents. + environment + A structure where information about all documents under the root is + saved, and used for cross-referencing. The environment is pickled + after the parsing stage, so that successive runs only need to read + and parse new and changed documents. - source directory - The directory which, including its subdirectories, contains all - source files for one Sphinx project. + source directory + The directory which, including its subdirectories, contains all + source files for one Sphinx project. Math ==== diff --git a/sphinx_immaterial/apidoc/object_toc.py b/sphinx_immaterial/apidoc/object_toc.py index 3ccaa763d..90c29bdea 100644 --- a/sphinx_immaterial/apidoc/object_toc.py +++ b/sphinx_immaterial/apidoc/object_toc.py @@ -294,7 +294,13 @@ def depart_term( node: docutils.nodes.term, super_func: html_translator_mixin.BaseVisitCallback[docutils.nodes.term], ) -> None: - self.add_permalink_ref(node, _("Permalink to this definition")) + next_node: docutils.nodes.Element = node.next_node(descend=False, siblings=True) + if not isinstance(next_node, docutils.nodes.classifier) and not ( + node.parent is not None + and node.parent.parent is not None + and isinstance(node.parent.parent.parent, sphinx.addnodes.glossary) + ): + self.add_permalink_ref(node, _("Permalink to this definition")) super_func(self, node)