@@ -451,6 +451,7 @@ def option_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
451
451
def ref_role (typ , rawtext , text , lineno , inliner , options = {}, content = []):
452
452
"""Reimplementation of Sphinx's ref role,"""
453
453
454
+ msg_list = []
454
455
match = _ref_re .match (text )
455
456
if match is not None :
456
457
text = match .groups ()[0 ].strip ()
@@ -459,6 +460,8 @@ def ref_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
459
460
else :
460
461
class RefVisitor (nodes .NodeVisitor , object ):
461
462
463
+ text = None
464
+
462
465
def __init__ (self , document , label ):
463
466
self ._label = label
464
467
super (RefVisitor , self ).__init__ (document )
@@ -479,10 +482,12 @@ def unknown_visit(self, node):
479
482
480
483
visitor = RefVisitor (inliner .document , text )
481
484
inliner .document .walk (visitor )
485
+ if visitor .text is None :
486
+ msg_list .append (inliner .reporter .error ("ref label {} is missing or not immediately before figure or section." .format (text )))
482
487
target = '#' + text
483
488
pnode = nodes .reference (text , visitor .text , internal = True , refuri = target )
484
489
pnode ['classes' ] = ['reference' ]
485
- return [pnode ], []
490
+ return [pnode ], msg_list
486
491
487
492
_abbr_re = re .compile ('\((.*)\)$' , re .S )
488
493
0 commit comments