Skip to content
Permalink
Browse files

some error handling, at least

  • Loading branch information
ralsina committed Dec 5, 2014
1 parent e31f8b3 commit 589a5bdf35bad38aeabc0d64c8a316adc3bbde5c
Showing with 6 additions and 1 deletion.
  1. +6 −1 v6/sphinx_roles/sphinx_roles.py
@@ -451,6 +451,7 @@ def option_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
def ref_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
"""Reimplementation of Sphinx's ref role,"""

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

text = None

def __init__(self, document, label):
self._label = label
super(RefVisitor, self).__init__(document)
@@ -479,10 +482,12 @@ def unknown_visit(self, node):

visitor = RefVisitor(inliner.document, text)
inliner.document.walk(visitor)
if visitor.text is None:
msg_list.append(inliner.reporter.error("ref label {} is missing or not immediately before figure or section.".format(text)))
target = '#' + text
pnode = nodes.reference(text, visitor.text, internal=True, refuri=target)
pnode['classes'] = ['reference']
return [pnode], []
return [pnode], msg_list

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

0 comments on commit 589a5bd

Please sign in to comment.
You can’t perform that action at this time.