Skip to content

Commit

Permalink
some error handling, at least
Browse files Browse the repository at this point in the history
  • Loading branch information
ralsina committed Dec 5, 2014
1 parent e31f8b3 commit 589a5bd
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion v6/sphinx_roles/sphinx_roles.py
Expand Up @@ -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()
Expand All @@ -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)
Expand All @@ -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)

Expand Down

0 comments on commit 589a5bd

Please sign in to comment.