Fix #2225: If the option does not begin with dash, linking is not performed

This commit is contained in:
Takeshi KOMIYA 2016-01-09 19:56:07 +09:00
parent e85ea7ed83
commit 7894f0bd9c
5 changed files with 47 additions and 25 deletions

View File

@ -45,6 +45,7 @@ Bugs fixed
* #2172: Fix dysfunctional admonition \py@lightbox in sphinx.sty. Thanks to jfbu.
* #2198,#2205: ``make gettext`` generate broken msgid for definition lists.
* #2062: Escape characters in doctests are treated incorrectly with Python 2.
* #2225: Fix if the option does not begin with dash, linking is not performed
Release 1.3.3 (released Dec 2, 2015)
====================================

View File

@ -242,9 +242,8 @@ objects:
.. rst:role:: option
A command-line option to an executable program. The leading hyphen(s) must
be included. This generates a link to a :rst:dir:`option` directive, if it
exists.
A command-line option to an executable program. This generates a link to
a :rst:dir:`option` directive, if it exists.
The following role creates a cross-reference to a term in a

View File

@ -210,10 +210,6 @@ class Program(Directive):
class OptionXRefRole(XRefRole):
def process_link(self, env, refnode, has_explicit_title, title, target):
# validate content
if not re.match(r'(.+ )?[-/+\w]', target):
env.warn_node('Malformed :option: %r, does not contain option '
'marker - or -- or / or +' % target, refnode)
refnode['std:program'] = env.ref_context.get('std:program')
return title, target
@ -664,22 +660,23 @@ class StandardDomain(Domain):
return make_refnode(builder, fromdocname, docname,
labelid, contnode)
elif typ == 'option':
progname = node.get('std:program')
target = target.strip()
# most obvious thing: we are a flag option without program
if target.startswith(('-', '/', '+')):
progname = node.get('std:program')
elif re.search(r'[-/+]', target):
try:
progname, target = re.split(r' (?=-|--|/|\+)', target, 1)
except ValueError:
return None
progname = ws_re.sub('-', progname.strip())
else:
progname = None
docname, labelid = self.data['progoptions'].get((progname, target),
('', ''))
docname, labelid = self.data['progoptions'].get((progname, target), ('', ''))
if not docname:
return None
commands = []
while ws_re.search(target):
subcommand, target = ws_re.split(target, 1)
commands.append(subcommand)
progname = "-".join(commands)
docname, labelid = self.data['progoptions'].get((progname, target),
('', ''))
if docname:
break
else:
return None
return make_refnode(builder, fromdocname, docname,
labelid, contnode)
else:

View File

@ -174,7 +174,17 @@ Others
.. option:: arg
Link to :option:`perl +p` and :option:`arg`.
Link to :option:`perl +p` and :option:`arg`
.. program:: hg
.. option:: commit
.. program:: git commit
.. option:: -p
Link to :option:`hg commit` and :option:`git commit -p`.
User markup

View File

@ -31,9 +31,7 @@ http://www.python.org/logo.png
reading included file u'.*?wrongenc.inc' seems to be wrong, try giving an \
:encoding: option\\n?
%(root)s/includes.txt:4: WARNING: download file not readable: .*?nonexisting.png
(%(root)s/markup.txt:\\d+: WARNING: Malformed :option: u'&option', does \
not contain option marker - or -- or / or \\+
%(root)s/undecodable.txt:3: WARNING: undecodable source characters, replacing \
(%(root)s/undecodable.txt:3: WARNING: undecodable source characters, replacing \
with "\\?": b?'here: >>>(\\\\|/)xbb<<<'
)?"""
@ -234,6 +232,23 @@ HTML_XPATH = {
(".//td[@class='field-body']/ul/li/strong", '^hour$'),
(".//td[@class='field-body']/ul/li/em", '^DuplicateType$'),
(".//td[@class='field-body']/ul/li/em", tail_check(r'.* Some parameter')),
# others
(".//a[@class='reference internal'][@href='#cmdoption-perl-arg-+p']/code/span",
'perl'),
(".//a[@class='reference internal'][@href='#cmdoption-perl-arg-+p']/code/span",
'\+p'),
(".//a[@class='reference internal'][@href='#cmdoption-perl-arg-arg']/code/span",
'arg'),
(".//a[@class='reference internal'][@href='#cmdoption-hg-arg-commit']/code/span",
'hg'),
(".//a[@class='reference internal'][@href='#cmdoption-hg-arg-commit']/code/span",
'commit'),
(".//a[@class='reference internal'][@href='#cmdoption-git-commit-p']/code/span",
'git'),
(".//a[@class='reference internal'][@href='#cmdoption-git-commit-p']/code/span",
'commit'),
(".//a[@class='reference internal'][@href='#cmdoption-git-commit-p']/code/span",
'-p'),
],
'contents.html': [
(".//meta[@name='hc'][@content='hcval']", ''),