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 a33d3363f01..e0d7d04fa28 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