diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-11-15 13:44:39 +0300 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2021-03-05 20:01:05 +0300 |
commit | d99132680d277db8409d17195948ee1d422dca66 (patch) | |
tree | ab5ec3a2f5cabe16358d1e03f57ae419b1a7ba39 /sphinx/transforms | |
parent | e1130972b2ad2e57db4ebe0a6fa83e1cb76aa6a3 (diff) |
Filter pending_xref_condition node on failed resolution
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 f8b01e81f..299b681ef 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.""" |