diff options
Diffstat (limited to 'sphinx/transforms')
-rw-r--r-- | sphinx/transforms/post_transforms/__init__.py | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/sphinx/transforms/post_transforms/__init__.py b/sphinx/transforms/post_transforms/__init__.py index 9ddde5928..b10c25b3e 100644 --- a/sphinx/transforms/post_transforms/__init__.py +++ b/sphinx/transforms/post_transforms/__init__.py @@ -22,10 +22,14 @@ from sphinx.locale import __ from sphinx.transforms import SphinxTransform from sphinx.util import logging from sphinx.util.docutils import SphinxTranslator -from sphinx.util.nodes import process_only_nodes +from sphinx.util.nodes import find_pending_xref_condition, process_only_nodes logger = logging.getLogger(__name__) +if False: + # For type annotation + from docutils.nodes import Node + class SphinxPostTransform(SphinxTransform): """A base class of post-transforms. @@ -97,8 +101,21 @@ class ReferencesResolver(SphinxPostTransform): if newnode is None: self.warn_missing_reference(refdoc, typ, target, node, domain) except NoUri: - newnode = contnode - node.replace_self(newnode or contnode) + newnode = None + + if newnode: + newnodes = [newnode] # type: List[Node] + else: + newnodes = [contnode] + if newnode is None and isinstance(node[0], addnodes.pending_xref_condition): + matched = find_pending_xref_condition(node, "*") + if matched: + newnodes = matched.children + else: + logger.warning(__('Could not determine the fallback text for the ' + 'cross-reference. Might be a bug.'), location=node) + + node.replace_self(newnodes) def resolve_anyref(self, refdoc: str, node: pending_xref, contnode: Element) -> Element: """Resolve reference generated by the "any" role.""" |