summaryrefslogtreecommitdiff
path: root/sphinx/domains
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2020-11-05 02:21:47 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2020-11-05 02:21:47 +0900
commit8bf84167a30aa05886fcc1ed8895c8c20e939d89 (patch)
tree51252d17e9c5a344395d64fe4225759cb04f1f4c /sphinx/domains
parentb93aa3137af650ea01f3a68bb14e822bffe81309 (diff)
parentab707be1e1def8c904b5df0c5ddeaf2edacca0f6 (diff)
downloadsphinx-git-8bf84167a30aa05886fcc1ed8895c8c20e939d89.tar.gz
Merge branch '3.x'
Diffstat (limited to 'sphinx/domains')
-rw-r--r--sphinx/domains/std.py17
1 files changed, 15 insertions, 2 deletions
diff --git a/sphinx/domains/std.py b/sphinx/domains/std.py
index 198548410..aa4793b66 100644
--- a/sphinx/domains/std.py
+++ b/sphinx/domains/std.py
@@ -595,8 +595,6 @@ class StandardDomain(Domain):
dangling_warnings = {
'term': 'term not in glossary: %(target)s',
- 'ref': 'undefined label: %(target)s (if the link has no caption '
- 'the label must precede a section header)',
'numref': 'undefined label: %(target)s',
'keyword': 'unknown keyword: %(target)s',
'doc': 'unknown document: %(target)s',
@@ -1075,8 +1073,23 @@ class StandardDomain(Domain):
return None
+def warn_missing_reference(app: "Sphinx", domain: Domain, node: pending_xref) -> bool:
+ if domain.name != 'std' or node['reftype'] != 'ref':
+ return None
+ else:
+ target = node['reftarget']
+ if target not in domain.anonlabels: # type: ignore
+ msg = __('undefined label: %s')
+ else:
+ msg = __('Failed to create a cross reference. A title or caption not found: %s')
+
+ logger.warning(msg % target, location=node, type='ref', subtype=node['reftype'])
+ return True
+
+
def setup(app: "Sphinx") -> Dict[str, Any]:
app.add_domain(StandardDomain)
+ app.connect('warn-missing-reference', warn_missing_reference)
return {
'version': 'builtin',