Skip to content

Commit

Permalink
Don't remove substitution_reference nodes (fix #7953)
Browse files Browse the repository at this point in the history
SubstitutionDefinitionsRemover is now a SphinxPostTransform, only
applied in the Sphinx builder, as was originally the case (see #4827).
  • Loading branch information
brechtm committed Sep 8, 2020
1 parent fabe685 commit 636682f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
14 changes: 14 additions & 0 deletions sphinx/builders/latex/transforms.py
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
15 changes: 1 addition & 14 deletions sphinx/transforms/references.py
Expand Up @@ -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

Expand All @@ -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."""

Expand All @@ -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)

Expand Down

0 comments on commit 636682f

Please sign in to comment.