diff options
| author | Georg Brandl <georg@python.org> | 2014-01-10 22:04:03 +0100 |
|---|---|---|
| committer | Georg Brandl <georg@python.org> | 2014-01-10 22:04:03 +0100 |
| commit | 4238b992b5e047c00a8a94df263e64fc8d1260db (patch) | |
| tree | f27a79a92803277d22d465efaed3e28f3999aac1 /sphinx/domains | |
| parent | 6df56547e6ce002a3ea190a69b708da13e7eb66d (diff) | |
| download | sphinx-4238b992b5e047c00a8a94df263e64fc8d1260db.tar.gz | |
Closes #933: Do not crash if an ``:option:`` value is malformed (contains spaces
but no option name).
Diffstat (limited to 'sphinx/domains')
| -rw-r--r-- | sphinx/domains/std.py | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/sphinx/domains/std.py b/sphinx/domains/std.py index ae67bf0e..50e519fa 100644 --- a/sphinx/domains/std.py +++ b/sphinx/domains/std.py @@ -190,17 +190,26 @@ class Program(Directive): class OptionXRefRole(XRefRole): innernodeclass = addnodes.literal_emphasis + def _split(self, text, refnode, env): + try: + program, target = re.split(' (?=-|--|/)', text, 1) + except ValueError: + env.warn_node('Malformed :option: %r, does not contain option ' + 'marker - or -- or /' % text, refnode) + return None, text + else: + program = ws_re.sub('-', program) + return program, target + def process_link(self, env, refnode, has_explicit_title, title, target): program = env.temp_data.get('std:program') if not has_explicit_title: if ' ' in title and not (title.startswith('/') or title.startswith('-')): - program, target = re.split(' (?=-|--|/)', title, 1) - program = ws_re.sub('-', program) + program, target = self._split(title, refnode, env) target = target.strip() elif ' ' in target: - program, target = re.split(' (?=-|--|/)', target, 1) - program = ws_re.sub('-', program) + program, target = self._split(target, refnode, env) refnode['refprogram'] = program return title, target |
