summaryrefslogtreecommitdiffstats
path: root/sphinx/builders/latex/transforms.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--sphinx/builders/latex/transforms.py25
1 files changed, 17 insertions, 8 deletions
diff --git a/sphinx/builders/latex/transforms.py b/sphinx/builders/latex/transforms.py
index ca1e4f3..83599d8 100644
--- a/sphinx/builders/latex/transforms.py
+++ b/sphinx/builders/latex/transforms.py
@@ -25,18 +25,20 @@ if TYPE_CHECKING:
from docutils.nodes import Element, Node
from sphinx.application import Sphinx
+ from sphinx.util.typing import ExtensionMetadata
URI_SCHEMES = ('mailto:', 'http:', 'https:', 'ftp:')
class FootnoteDocnameUpdater(SphinxTransform):
"""Add docname to footnote and footnote_reference nodes."""
+
default_priority = 700
TARGET_NODES = (nodes.footnote, nodes.footnote_reference)
def apply(self, **kwargs: Any) -> None:
matcher = NodeMatcher(*self.TARGET_NODES)
- for node in self.document.findall(matcher): # type: Element
+ for node in matcher.findall(self.document):
node['docname'] = self.env.docname
@@ -59,6 +61,7 @@ class ShowUrlsTransform(SphinxPostTransform):
.. note:: This transform is used for integrated doctree
"""
+
default_priority = 400
formats = ('latex',)
@@ -112,7 +115,7 @@ class ShowUrlsTransform(SphinxPostTransform):
node = node.parent
try:
- source = node['source'] # type: ignore[index]
+ source = node['source']
except TypeError:
raise ValueError(__('Failed to get a docname!')) from None
raise ValueError(__('Failed to get a docname '
@@ -509,6 +512,7 @@ class BibliographyTransform(SphinxPostTransform):
<citation>
...
"""
+
default_priority = 750
formats = ('latex',)
@@ -519,7 +523,7 @@ class BibliographyTransform(SphinxPostTransform):
citations += node
if len(citations) > 0:
- self.document += citations
+ self.document += citations # type: ignore[attr-defined]
class CitationReferenceTransform(SphinxPostTransform):
@@ -528,13 +532,14 @@ class CitationReferenceTransform(SphinxPostTransform):
To handle citation reference easily on LaTeX writer, this converts
pending_xref nodes to citation_reference.
"""
+
default_priority = 5 # before ReferencesResolver
formats = ('latex',)
def run(self, **kwargs: Any) -> None:
domain = cast(CitationDomain, self.env.get_domain('citation'))
matcher = NodeMatcher(addnodes.pending_xref, refdomain='citation', reftype='ref')
- for node in self.document.findall(matcher): # type: addnodes.pending_xref
+ for node in matcher.findall(self.document):
docname, labelid, _ = domain.citations.get(node['reftarget'], ('', '', 0))
if docname:
citation_ref = nodes.citation_reference('', '', *node.children,
@@ -548,6 +553,7 @@ class MathReferenceTransform(SphinxPostTransform):
To handle math reference easily on LaTeX writer, this converts pending_xref
nodes to math_reference.
"""
+
default_priority = 5 # before ReferencesResolver
formats = ('latex',)
@@ -563,18 +569,20 @@ class MathReferenceTransform(SphinxPostTransform):
class LiteralBlockTransform(SphinxPostTransform):
"""Replace container nodes for literal_block by captioned_literal_block."""
+
default_priority = 400
formats = ('latex',)
def run(self, **kwargs: Any) -> None:
matcher = NodeMatcher(nodes.container, literal_block=True)
- for node in self.document.findall(matcher): # type: nodes.container
+ for node in matcher.findall(self.document):
newnode = captioned_literal_block('', *node.children, **node.attributes)
node.replace_self(newnode)
class DocumentTargetTransform(SphinxPostTransform):
"""Add :doc label to the first section of each document."""
+
default_priority = 400
formats = ('latex',)
@@ -586,10 +594,10 @@ class DocumentTargetTransform(SphinxPostTransform):
class IndexInSectionTitleTransform(SphinxPostTransform):
- """Move index nodes in section title to outside of the title.
+ r"""Move index nodes in section title to outside of the title.
LaTeX index macro is not compatible with some handling of section titles
- such as uppercasing done on LaTeX side (cf. fncychap handling of ``\\chapter``).
+ such as uppercasing done on LaTeX side (cf. fncychap handling of ``\chapter``).
Moving the index node to after the title node fixes that.
Before::
@@ -611,6 +619,7 @@ class IndexInSectionTitleTransform(SphinxPostTransform):
blah blah blah
...
"""
+
default_priority = 400
formats = ('latex',)
@@ -623,7 +632,7 @@ class IndexInSectionTitleTransform(SphinxPostTransform):
node.parent.insert(i + 1, index)
-def setup(app: Sphinx) -> dict[str, Any]:
+def setup(app: Sphinx) -> ExtensionMetadata:
app.add_transform(FootnoteDocnameUpdater)
app.add_post_transform(SubstitutionDefinitionsRemover)
app.add_post_transform(BibliographyTransform)