mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2026-09-03 20:52:55 -05:00
Closes #1357: Option names documented by :rst:dir:option are now again allowed to
not start with a dash or slash, and referencing them will work correctly.
This commit is contained in:
@@ -8,6 +8,8 @@ Bugs fixed
|
|||||||
the full relative path and not the basename.
|
the full relative path and not the basename.
|
||||||
* PR#212: Fix traceback with autodoc and ``__init__`` methods without docstring.
|
* PR#212: Fix traceback with autodoc and ``__init__`` methods without docstring.
|
||||||
* PR#213: Fix a missing import in the setup command.
|
* PR#213: Fix a missing import in the setup command.
|
||||||
|
* #1357: Option names documented by :rst:dir:`option` are now again allowed to
|
||||||
|
not start with a dash or slash, and referencing them will work correctly.
|
||||||
|
|
||||||
Documentation
|
Documentation
|
||||||
-------------
|
-------------
|
||||||
|
|||||||
+9
-5
@@ -632,16 +632,20 @@ There is a set of directives allowing documenting command-line programs:
|
|||||||
|
|
||||||
.. rst:directive:: .. option:: name args, name args, ...
|
.. rst:directive:: .. option:: name args, name args, ...
|
||||||
|
|
||||||
Describes a command line option or switch. Option argument names should be
|
Describes a command line argument or switch. Option argument names should be
|
||||||
enclosed in angle brackets. Example::
|
enclosed in angle brackets. Examples::
|
||||||
|
|
||||||
|
.. option:: dest_dir
|
||||||
|
|
||||||
|
Destination directory.
|
||||||
|
|
||||||
.. option:: -m <module>, --module <module>
|
.. option:: -m <module>, --module <module>
|
||||||
|
|
||||||
Run a module as a script.
|
Run a module as a script.
|
||||||
|
|
||||||
The directive will create a cross-reference target named after the *first*
|
The directive will create cross-reference targets for the given options,
|
||||||
option, referencable by :rst:role:`option` (in the example case, you'd use
|
referencable by :rst:role:`option` (in the example case, you'd use something
|
||||||
something like ``:option:`-m```).
|
like ``:option:`dest_dir```, ``:option:`-m```, or ``:option:`--module```).
|
||||||
|
|
||||||
.. rst:directive:: .. envvar:: name
|
.. rst:directive:: .. envvar:: name
|
||||||
|
|
||||||
|
|||||||
+23
-15
@@ -27,7 +27,7 @@ from sphinx.util.compat import Directive
|
|||||||
|
|
||||||
|
|
||||||
# RE for option descriptions
|
# RE for option descriptions
|
||||||
option_desc_re = re.compile(r'((?:/|-|--)[-_a-zA-Z0-9]+)(\s*.*)')
|
option_desc_re = re.compile(r'((?:/|-|--)?[-_a-zA-Z0-9]+)(\s*.*)')
|
||||||
|
|
||||||
|
|
||||||
class GenericObject(ObjectDescription):
|
class GenericObject(ObjectDescription):
|
||||||
@@ -143,7 +143,7 @@ class Cmdoption(ObjectDescription):
|
|||||||
self.env.warn(
|
self.env.warn(
|
||||||
self.env.docname,
|
self.env.docname,
|
||||||
'Malformed option description %r, should '
|
'Malformed option description %r, should '
|
||||||
'look like "-opt args", "--opt args" or '
|
'look like "opt", "-opt args", "--opt args" or '
|
||||||
'"/opt args"' % potential_option, self.lineno)
|
'"/opt args"' % potential_option, self.lineno)
|
||||||
continue
|
continue
|
||||||
optname, args = m.groups()
|
optname, args = m.groups()
|
||||||
@@ -153,25 +153,33 @@ class Cmdoption(ObjectDescription):
|
|||||||
signode += addnodes.desc_addname(args, args)
|
signode += addnodes.desc_addname(args, args)
|
||||||
if not count:
|
if not count:
|
||||||
firstname = optname
|
firstname = optname
|
||||||
|
signode['allnames'] = [optname]
|
||||||
|
else:
|
||||||
|
signode['allnames'].append(optname)
|
||||||
count += 1
|
count += 1
|
||||||
if not firstname:
|
if not firstname:
|
||||||
raise ValueError
|
raise ValueError
|
||||||
return firstname
|
return firstname
|
||||||
|
|
||||||
def add_target_and_index(self, name, sig, signode):
|
def add_target_and_index(self, firstname, sig, signode):
|
||||||
targetname = name.replace('/', '-')
|
|
||||||
currprogram = self.env.temp_data.get('std:program')
|
currprogram = self.env.temp_data.get('std:program')
|
||||||
if currprogram:
|
for optname in signode.get('allnames', []):
|
||||||
targetname = '-' + currprogram + targetname
|
targetname = optname.replace('/', '-')
|
||||||
targetname = 'cmdoption' + targetname
|
if not targetname.startswith('-'):
|
||||||
signode['ids'].append(targetname)
|
targetname = '-arg-' + targetname
|
||||||
self.state.document.note_explicit_target(signode)
|
if currprogram:
|
||||||
self.indexnode['entries'].append(
|
targetname = '-' + currprogram + targetname
|
||||||
('pair', _('%scommand line option; %s') %
|
targetname = 'cmdoption' + targetname
|
||||||
((currprogram and currprogram + ' ' or ''), sig),
|
signode['ids'].append(targetname)
|
||||||
targetname, ''))
|
self.state.document.note_explicit_target(signode)
|
||||||
self.env.domaindata['std']['progoptions'][currprogram, name] = \
|
self.env.domaindata['std']['progoptions'][currprogram, optname] = \
|
||||||
self.env.docname, targetname
|
self.env.docname, targetname
|
||||||
|
# create only one index entry for the whole option
|
||||||
|
if optname == firstname:
|
||||||
|
self.indexnode['entries'].append(
|
||||||
|
('pair', _('%scommand line option; %s') %
|
||||||
|
((currprogram and currprogram + ' ' or ''), sig),
|
||||||
|
targetname, ''))
|
||||||
|
|
||||||
|
|
||||||
class Program(Directive):
|
class Program(Directive):
|
||||||
|
|||||||
Reference in New Issue
Block a user