mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Add :type: option for rst:directive:option directive
This commit is contained in:
@@ -1444,6 +1444,20 @@ The reStructuredText domain (name **rst**) provides the following directives:
|
||||
|
||||
.. rst:directive:option:: glob
|
||||
|
||||
.. rubric:: options
|
||||
|
||||
.. rst:directive:option:: type
|
||||
:type: description for the option of directive
|
||||
|
||||
Describe the type of option value.
|
||||
|
||||
For example::
|
||||
|
||||
.. rst:directive:: toctree
|
||||
|
||||
.. rst:directive:option:: maxdepth
|
||||
:type: integer or no value
|
||||
|
||||
.. versionadded:: 2.1
|
||||
|
||||
.. rst:directive:: .. rst:role:: name
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
import re
|
||||
from typing import cast
|
||||
|
||||
from docutils.parsers.rst import directives
|
||||
|
||||
from sphinx import addnodes
|
||||
from sphinx.directives import ObjectDescription
|
||||
from sphinx.domains import Domain, ObjType
|
||||
@@ -115,6 +117,11 @@ class ReSTDirectiveOption(ReSTMarkup):
|
||||
"""
|
||||
Description of an option for reST directive.
|
||||
"""
|
||||
option_spec = ReSTMarkup.option_spec.copy()
|
||||
option_spec.update({
|
||||
'type': directives.unchanged,
|
||||
})
|
||||
|
||||
def handle_signature(self, sig, signode):
|
||||
# type: (str, addnodes.desc_signature) -> str
|
||||
try:
|
||||
@@ -125,6 +132,9 @@ class ReSTDirectiveOption(ReSTMarkup):
|
||||
signode += addnodes.desc_name(':%s:' % name, ':%s:' % name)
|
||||
if argument:
|
||||
signode += addnodes.desc_annotation(' ' + argument, ' ' + argument)
|
||||
if self.options.get('type'):
|
||||
text = ' (%s)' % self.options['type']
|
||||
signode += addnodes.desc_annotation(text, text)
|
||||
return name
|
||||
|
||||
def add_target_and_index(self, name, sig, signode):
|
||||
@@ -179,8 +189,9 @@ class ReSTDomain(Domain):
|
||||
label = 'reStructuredText'
|
||||
|
||||
object_types = {
|
||||
'directive': ObjType(_('directive'), 'dir'),
|
||||
'role': ObjType(_('role'), 'role'),
|
||||
'directive': ObjType(_('directive'), 'dir'),
|
||||
'directive:option': ObjType(_('directive-option'), 'dir'),
|
||||
'role': ObjType(_('role'), 'role'),
|
||||
}
|
||||
directives = {
|
||||
'directive': ReSTDirective,
|
||||
|
||||
@@ -95,6 +95,21 @@ def test_rst_directive_option_with_argument(app):
|
||||
domain="rst", objtype="directive:option", noindex=False)
|
||||
|
||||
|
||||
def test_rst_directive_option_type(app):
|
||||
text = (".. rst:directive:option:: foo\n"
|
||||
" :type: directives.flags\n")
|
||||
doctree = restructuredtext.parse(app, text)
|
||||
assert_node(doctree, (addnodes.index,
|
||||
[desc, ([desc_signature, ([desc_name, ":foo:"],
|
||||
[desc_annotation, " (directives.flags)"])],
|
||||
[desc_content, ()])]))
|
||||
assert_node(doctree[0],
|
||||
entries=[("single", ":foo: (directive option)",
|
||||
"directive:option--foo", "", "F")])
|
||||
assert_node(doctree[1], addnodes.desc, desctype="directive:option",
|
||||
domain="rst", objtype="directive:option", noindex=False)
|
||||
|
||||
|
||||
def test_rst_directive_and_directive_option(app):
|
||||
text = (".. rst:directive:: foo\n"
|
||||
"\n"
|
||||
|
||||
Reference in New Issue
Block a user