Skip to content

Commit

Permalink
Merge pull request #8354 from tk0miya/8183
Browse files Browse the repository at this point in the history
Don't remove substitution_reference nodes (refined)
  • Loading branch information
tk0miya authored Nov 1, 2020
2 parents 4c2076b + 87121c3 commit 0c5de26
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
14 changes: 14 additions & 0 deletions sphinx/builders/latex/transforms.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
9 changes: 9 additions & 0 deletions sphinx/writers/texinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
'<SYSTEM MESSAGE: %s>\n'
Expand Down
3 changes: 3 additions & 0 deletions sphinx/writers/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 0c5de26

Please sign in to comment.