Skip to content

Commit 589a5bd

Browse files
committedDec 5, 2014
some error handling, at least
1 parent e31f8b3 commit 589a5bd

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed
 

Diff for: ‎v6/sphinx_roles/sphinx_roles.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ def option_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
451451
def ref_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
452452
"""Reimplementation of Sphinx's ref role,"""
453453

454+
msg_list = []
454455
match = _ref_re.match(text)
455456
if match is not None:
456457
text = match.groups()[0].strip()
@@ -459,6 +460,8 @@ def ref_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
459460
else:
460461
class RefVisitor(nodes.NodeVisitor, object):
461462

463+
text = None
464+
462465
def __init__(self, document, label):
463466
self._label = label
464467
super(RefVisitor, self).__init__(document)
@@ -479,10 +482,12 @@ def unknown_visit(self, node):
479482

480483
visitor = RefVisitor(inliner.document, text)
481484
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)))
482487
target = '#' + text
483488
pnode = nodes.reference(text, visitor.text, internal=True, refuri=target)
484489
pnode['classes'] = ['reference']
485-
return [pnode], []
490+
return [pnode], msg_list
486491

487492
_abbr_re = re.compile('\((.*)\)$', re.S)
488493

0 commit comments

Comments
 (0)
Please sign in to comment.