From c9d8eac5ac08583db3fd6fd48164a4c475436ddb Mon Sep 17 00:00:00 2001 From: Brecht Machiels Date: Tue, 8 Sep 2020 17:27:57 +0200 Subject: [PATCH] Don't remove substitution_reference nodes (fix #7953) SubstitutionDefinitionsRemover is now a SphinxPostTransform, only applied in the Sphinx builder, as was originally the case (see #4827). --- sphinx/builders/latex/transforms.py | 14 ++++++++++++++ sphinx/transforms/references.py | 15 +-------------- sphinx/writers/texinfo.py | 9 +++++++++ sphinx/writers/text.py | 3 +++ 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/sphinx/builders/latex/transforms.py b/sphinx/builders/latex/transforms.py index 28841ad77ef..174483be6a2 100644 --- a/sphinx/builders/latex/transforms.py +++ b/sphinx/builders/latex/transforms.py @@ -13,6 +13,7 @@ from docutils import nodes from docutils.nodes import Element, Node +from docutils.transforms.references import Substitutions from sphinx import addnodes from sphinx.application import Sphinx @@ -38,6 +39,18 @@ def apply(self, **kwargs: Any) -> None: node['docname'] = self.env.docname +class SubstitutionDefinitionsRemover(SphinxPostTransform): + """Remove ``substitution_definition node from doctrees.""" + + # should be invoked after Substitutions process + default_priority = Substitutions.default_priority + 1 + builders = ('latex',) + + def apply(self, **kwargs: Any) -> None: + for node in self.document.traverse(nodes.substitution_definition): + node.parent.remove(node) + + class ShowUrlsTransform(SphinxPostTransform): """Expand references to inline text or footnotes. @@ -602,6 +615,7 @@ def apply(self, **kwargs: Any) -> None: def setup(app: Sphinx) -> Dict[str, Any]: app.add_transform(FootnoteDocnameUpdater) + app.add_post_transform(SubstitutionDefinitionsRemover) app.add_post_transform(BibliographyTransform) app.add_post_transform(CitationReferenceTransform) app.add_post_transform(DocumentTargetTransform) diff --git a/sphinx/transforms/references.py b/sphinx/transforms/references.py index e74d9657d32..b6129b0bcb7 100644 --- a/sphinx/transforms/references.py +++ b/sphinx/transforms/references.py @@ -10,8 +10,7 @@ from typing import Any, Dict -from docutils import nodes -from docutils.transforms.references import DanglingReferences, Substitutions +from docutils.transforms.references import DanglingReferences from sphinx.transforms import SphinxTransform @@ -20,17 +19,6 @@ from sphinx.application import Sphinx -class SubstitutionDefinitionsRemover(SphinxTransform): - """Remove ``substitution_definition node from doctrees.""" - - # should be invoked after Substitutions process - default_priority = Substitutions.default_priority + 1 - - def apply(self, **kwargs: Any) -> None: - for node in self.document.traverse(nodes.substitution_definition): - node.parent.remove(node) - - class SphinxDanglingReferences(DanglingReferences): """DanglingReferences transform which does not output info messages.""" @@ -56,7 +44,6 @@ def apply(self, **kwargs: Any) -> None: def setup(app: "Sphinx") -> Dict[str, Any]: - app.add_transform(SubstitutionDefinitionsRemover) app.add_transform(SphinxDanglingReferences) app.add_transform(SphinxDomains) diff --git a/sphinx/writers/texinfo.py b/sphinx/writers/texinfo.py index 8c52a0868a2..aef13f3e5c6 100644 --- a/sphinx/writers/texinfo.py +++ b/sphinx/writers/texinfo.py @@ -1242,6 +1242,15 @@ def visit_legend(self, node: Element) -> None: def depart_legend(self, node: Element) -> None: pass + def visit_substitution_reference(self, node: Element) -> None: + pass + + def depart_substitution_reference(self, node: Element) -> None: + pass + + def visit_substitution_definition(self, node: Element) -> None: + raise nodes.SkipNode + def visit_system_message(self, node: Element) -> None: self.body.append('\n@verbatim\n' '\n' diff --git a/sphinx/writers/text.py b/sphinx/writers/text.py index 796362260a7..9cb066e0bd3 100644 --- a/sphinx/writers/text.py +++ b/sphinx/writers/text.py @@ -1013,6 +1013,9 @@ def visit_index(self, node: Element) -> None: def visit_toctree(self, node: Element) -> None: raise nodes.SkipNode + def visit_substitution_definition(self, node: Element) -> None: + raise nodes.SkipNode + def visit_pending_xref(self, node: Element) -> None: pass