This commit is contained in:
Georg Brandl 2015-03-08 15:38:28 +01:00
commit 3437872b30
14 changed files with 162 additions and 86 deletions

View File

@ -35,6 +35,8 @@ Bugs fixed
begin with -, / or +. Thanks to Takayuki Hirai. begin with -, / or +. Thanks to Takayuki Hirai.
* #1753: C++, added missing support for more complex declarations. * #1753: C++, added missing support for more complex declarations.
* #1700: Add ``:caption:`` option for :rst:dir:`toctree`. * #1700: Add ``:caption:`` option for :rst:dir:`toctree`.
* #1742: ``:name:`` option is provided for :rst:dir:`toctree`, :rst:dir:`code-block` and
:rst:dir:`literalinclude` dirctives.
Release 1.3b3 (released Feb 24, 2015) Release 1.3b3 (released Feb 24, 2015)

View File

@ -214,23 +214,26 @@ Includes
The ``lineno-match`` option. The ``lineno-match`` option.
Showing a file name Caption and name
^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^
.. versionadded:: 1.3 .. versionadded:: 1.3
A ``caption`` option can be given to show that name before the code block. For A ``caption`` option can be given to show that name before the code block.
example:: A ``name`` option can be provided implicit target name that can be referenced
by using :rst:role:`ref`.
For example::
.. code-block:: python .. code-block:: python
:caption: this.py :caption: this.py
:name: this-py
print 'Explicit is better than implicit.' print 'Explicit is better than implicit.'
:rst:dir:`literalinclude` also supports the ``caption`` option, with the :rst:dir:`literalinclude` also supports the ``caption`` and ``name`` option.
additional feature that if you leave the value empty, the shown filename will be ``caption`` has a additional feature that if you leave the value empty, the shown
exactly the one given as an argument. filename will be exactly the one given as an argument.
Dedent Dedent

View File

@ -85,10 +85,13 @@ tables of contents. The ``toctree`` directive is the central element.
**Additional options** **Additional options**
You can use ``caption`` option to provide toctree caption:: You can use ``caption`` option to provide toctree caption and you can use
``name`` option to provide implicit target name that can be referenced by
using :rst:role:`ref`::
.. toctree:: .. toctree::
:caption: Table of Contents :caption: Table of Contents
:name: mastertoc
foo foo
@ -176,7 +179,7 @@ tables of contents. The ``toctree`` directive is the central element.
Added "includehidden" option. Added "includehidden" option.
.. versionchanged:: 1.3 .. versionchanged:: 1.3
Added "caption" option. Added "caption" and "name" option.
Special names Special names
------------- -------------

View File

@ -93,6 +93,7 @@ class CodeBlock(Directive):
'lineno-start': int, 'lineno-start': int,
'emphasize-lines': directives.unchanged_required, 'emphasize-lines': directives.unchanged_required,
'caption': directives.unchanged_required, 'caption': directives.unchanged_required,
'name': directives.unchanged,
} }
def run(self): def run(self):
@ -127,8 +128,13 @@ class CodeBlock(Directive):
caption = self.options.get('caption') caption = self.options.get('caption')
if caption: if caption:
self.options.setdefault('name', nodes.fully_normalize_name(caption))
literal = container_wrapper(self, literal, caption) literal = container_wrapper(self, literal, caption)
# literal will be note_implicit_target that is linked from caption and numref.
# when options['name'] is provided, it should be primary ID.
self.add_name(literal)
return [literal] return [literal]
@ -159,6 +165,7 @@ class LiteralInclude(Directive):
'append': directives.unchanged_required, 'append': directives.unchanged_required,
'emphasize-lines': directives.unchanged_required, 'emphasize-lines': directives.unchanged_required,
'caption': directives.unchanged, 'caption': directives.unchanged,
'name': directives.unchanged,
'diff': directives.unchanged_required, 'diff': directives.unchanged_required,
} }
@ -332,10 +339,14 @@ class LiteralInclude(Directive):
caption = self.options.get('caption') caption = self.options.get('caption')
if caption is not None: if caption is not None:
if caption: if not caption:
caption = self.arguments[0]
self.options.setdefault('name', nodes.fully_normalize_name(caption))
retnode = container_wrapper(self, retnode, caption) retnode = container_wrapper(self, retnode, caption)
else:
retnode = container_wrapper(self, retnode, self.arguments[0]) # retnode will be note_implicit_target that is linked from caption and numref.
# when options['name'] is provided, it should be primary ID.
self.add_name(retnode)
return [retnode] return [retnode]

View File

@ -40,7 +40,8 @@ class TocTree(Directive):
final_argument_whitespace = False final_argument_whitespace = False
option_spec = { option_spec = {
'maxdepth': int, 'maxdepth': int,
'caption': str, 'name': directives.unchanged,
'caption': directives.unchanged_required,
'glob': directives.flag, 'glob': directives.flag,
'hidden': directives.flag, 'hidden': directives.flag,
'includehidden': directives.flag, 'includehidden': directives.flag,
@ -54,7 +55,7 @@ class TocTree(Directive):
glob = 'glob' in self.options glob = 'glob' in self.options
caption = self.options.get('caption') caption = self.options.get('caption')
if caption: if caption:
self.options['name'] = nodes.fully_normalize_name(caption) self.options.setdefault('name', nodes.fully_normalize_name(caption))
ret = [] ret = []
# (title, ref) pairs, where ref may be a document, or an external link, # (title, ref) pairs, where ref may be a document, or an external link,

View File

@ -503,7 +503,7 @@ class ASTOperatorBuildIn(ASTBase):
def get_name_no_template(self): def get_name_no_template(self):
return text_type(self) return text_type(self)
def describe_signature(self, signode, mode, env, prefix): def describe_signature(self, signode, mode, env, prefix, parentScope):
_verify_description_mode(mode) _verify_description_mode(mode)
identifier = text_type(self) identifier = text_type(self)
if mode == 'lastIsName': if mode == 'lastIsName':
@ -528,7 +528,7 @@ class ASTOperatorType(ASTBase):
def get_name_no_template(self): def get_name_no_template(self):
return text_type(self) return text_type(self)
def describe_signature(self, signode, mode, env, prefix): def describe_signature(self, signode, mode, env, prefix, parentScope):
_verify_description_mode(mode) _verify_description_mode(mode)
identifier = text_type(self) identifier = text_type(self)
if mode == 'lastIsName': if mode == 'lastIsName':
@ -552,7 +552,7 @@ class ASTTemplateArgConstant(ASTBase):
# juse it verbatim for now # juse it verbatim for now
return u'X' + text_type(self) + u'E' return u'X' + text_type(self) + u'E'
def describe_signature(self, signode, mode, env): def describe_signature(self, signode, mode, env, parentScope):
_verify_description_mode(mode) _verify_description_mode(mode)
signode += nodes.Text(text_type(self)) signode += nodes.Text(text_type(self))
@ -569,7 +569,7 @@ class ASTNestedNameElementEmpty(ASTBase):
def __unicode__(self): def __unicode__(self):
return u'' return u''
def describe_signature(self, signode, mode, env, prefix): def describe_signature(self, signode, mode, env, prefix, parentScope):
pass pass
@ -624,15 +624,14 @@ class ASTNestedNameElement(ASTBase):
def get_name_no_template(self): def get_name_no_template(self):
return text_type(self.identifier) return text_type(self.identifier)
def describe_signature(self, signode, mode, env, prefix): def describe_signature(self, signode, mode, env, prefix, parentScope):
_verify_description_mode(mode) _verify_description_mode(mode)
if mode == 'markType': if mode == 'markType':
targetText = prefix + text_type(self) targetText = prefix + text_type(self)
pnode = addnodes.pending_xref( pnode = addnodes.pending_xref(
'', refdomain='cpp', reftype='type', '', refdomain='cpp', reftype='type',
reftarget=targetText, modname=None, classname=None) reftarget=targetText, modname=None, classname=None)
if env: # during testing we don't have an env, do we? pnode['cpp:parent'] = [parentScope]
pnode['cpp:parent'] = env.ref_context.get('cpp:parent')
pnode += nodes.Text(text_type(self.identifier)) pnode += nodes.Text(text_type(self.identifier))
signode += pnode signode += pnode
elif mode == 'lastIsName': elif mode == 'lastIsName':
@ -647,7 +646,8 @@ class ASTNestedNameElement(ASTBase):
if not first: if not first:
signode += nodes.Text(', ') signode += nodes.Text(', ')
first = False first = False
a.describe_signature(signode, 'markType', env) a.describe_signature(signode, 'markType', env,
parentScope=parentScope)
signode += nodes.Text('>') signode += nodes.Text('>')
@ -702,7 +702,7 @@ class ASTNestedName(ASTBase):
def __unicode__(self): def __unicode__(self):
return u'::'.join([text_type(n) for n in self.names]) return u'::'.join([text_type(n) for n in self.names])
def describe_signature(self, signode, mode, env): def describe_signature(self, signode, mode, env, parentScope):
_verify_description_mode(mode) _verify_description_mode(mode)
if mode == 'lastIsName': if mode == 'lastIsName':
addname = u'::'.join([text_type(n) for n in self.names[:-1]]) addname = u'::'.join([text_type(n) for n in self.names[:-1]])
@ -710,7 +710,8 @@ class ASTNestedName(ASTBase):
addname += u'::' addname += u'::'
name = text_type(self.names[-1]) name = text_type(self.names[-1])
signode += addnodes.desc_addname(addname, addname) signode += addnodes.desc_addname(addname, addname)
self.names[-1].describe_signature(signode, mode, env, '') self.names[-1].describe_signature(signode, mode, env, '',
parentScope=parentScope)
elif mode == 'noneIsName': elif mode == 'noneIsName':
name = text_type(self) name = text_type(self)
signode += nodes.Text(name) signode += nodes.Text(name)
@ -729,7 +730,8 @@ class ASTNestedName(ASTBase):
prefix += '::' prefix += '::'
first = False first = False
if name != '': if name != '':
name.describe_signature(signode, mode, env, prefix) name.describe_signature(signode, mode, env, prefix,
parentScope=parentScope)
prefix += text_type(name) prefix += text_type(name)
else: else:
raise Exception('Unknown description mode: %s' % mode) raise Exception('Unknown description mode: %s' % mode)
@ -759,7 +761,7 @@ class ASTTrailingTypeSpecFundamental(ASTBase):
'parser should have rejected it.' % self.name) 'parser should have rejected it.' % self.name)
return _id_fundamental_v2[self.name] return _id_fundamental_v2[self.name]
def describe_signature(self, signode, mode, env): def describe_signature(self, signode, mode, env, parentScope):
signode += nodes.Text(text_type(self.name)) signode += nodes.Text(text_type(self.name))
@ -786,11 +788,12 @@ class ASTTrailingTypeSpecName(ASTBase):
res.append(text_type(self.nestedName)) res.append(text_type(self.nestedName))
return u''.join(res) return u''.join(res)
def describe_signature(self, signode, mode, env): def describe_signature(self, signode, mode, env, parentScope):
if self.prefix: if self.prefix:
signode += addnodes.desc_annotation(self.prefix, self.prefix) signode += addnodes.desc_annotation(self.prefix, self.prefix)
signode += nodes.Text(' ') signode += nodes.Text(' ')
self.nestedName.describe_signature(signode, mode, env) self.nestedName.describe_signature(signode, mode, env,
parentScope=parentScope)
class ASTFunctinoParameter(ASTBase): class ASTFunctinoParameter(ASTBase):
@ -816,12 +819,13 @@ class ASTFunctinoParameter(ASTBase):
else: else:
return text_type(self.arg) return text_type(self.arg)
def describe_signature(self, signode, mode, env): def describe_signature(self, signode, mode, env, parentScope):
_verify_description_mode(mode) _verify_description_mode(mode)
if self.ellipsis: if self.ellipsis:
signode += nodes.Text('...') signode += nodes.Text('...')
else: else:
self.arg.describe_signature(signode, mode, env) self.arg.describe_signature(signode, mode, env,
parentScope=parentScope)
class ASTParametersQualifiers(ASTBase): class ASTParametersQualifiers(ASTBase):
@ -905,15 +909,17 @@ class ASTParametersQualifiers(ASTBase):
res.append(self.initializer) res.append(self.initializer)
return u''.join(res) return u''.join(res)
def describe_signature(self, signode, mode, env): def describe_signature(self, signode, mode, env, parentScope):
_verify_description_mode(mode) _verify_description_mode(mode)
paramlist = addnodes.desc_parameterlist() paramlist = addnodes.desc_parameterlist()
for arg in self.args: for arg in self.args:
param = addnodes.desc_parameter('', '', noemph=True) param = addnodes.desc_parameter('', '', noemph=True)
if mode == 'lastIsName': # i.e., outer-function params if mode == 'lastIsName': # i.e., outer-function params
arg.describe_signature(param, 'param', env) arg.describe_signature(param, 'param', env,
parentScope=parentScope)
else: else:
arg.describe_signature(param, 'markType', env) arg.describe_signature(param, 'markType', env,
parentScope=parentScope)
paramlist += param paramlist += param
signode += paramlist signode += paramlist
@ -1058,7 +1064,7 @@ class ASTDeclSpecs(ASTBase):
res.append(r) res.append(r)
return "".join(res) return "".join(res)
def describe_signature(self, signode, mode, env): def describe_signature(self, signode, mode, env, parentScope):
_verify_description_mode(mode) _verify_description_mode(mode)
modifiers = [] modifiers = []
@ -1076,7 +1082,8 @@ class ASTDeclSpecs(ASTBase):
if self.trailingTypeSpec: if self.trailingTypeSpec:
if len(modifiers) > 0: if len(modifiers) > 0:
signode += nodes.Text(' ') signode += nodes.Text(' ')
self.trailingTypeSpec.describe_signature(signode, mode, env) self.trailingTypeSpec.describe_signature(signode, mode, env,
parentScope=parentScope)
modifiers = [] modifiers = []
self.rightSpecs.describe_signature(modifiers) self.rightSpecs.describe_signature(modifiers)
if len(modifiers) > 0: if len(modifiers) > 0:
@ -1176,10 +1183,11 @@ class ASTDeclaratorPtr(ASTBase):
def is_function_type(self): def is_function_type(self):
return self.next.is_function_type() return self.next.is_function_type()
def describe_signature(self, signode, mode, env): def describe_signature(self, signode, mode, env, parentScope):
_verify_description_mode(mode) _verify_description_mode(mode)
signode += nodes.Text("*") signode += nodes.Text("*")
self.next.describe_signature(signode, mode, env) self.next.describe_signature(signode, mode, env,
parentScope=parentScope)
class ASTDeclaratorRef(ASTBase): class ASTDeclaratorRef(ASTBase):
@ -1228,10 +1236,11 @@ class ASTDeclaratorRef(ASTBase):
def is_function_type(self): def is_function_type(self):
return self.next.is_function_type() return self.next.is_function_type()
def describe_signature(self, signode, mode, env): def describe_signature(self, signode, mode, env, parentScope):
_verify_description_mode(mode) _verify_description_mode(mode)
signode += nodes.Text("&") signode += nodes.Text("&")
self.next.describe_signature(signode, mode, env) self.next.describe_signature(signode, mode, env,
parentScope=parentScope)
class ASTDeclaratorParamPack(ASTBase): class ASTDeclaratorParamPack(ASTBase):
@ -1283,12 +1292,13 @@ class ASTDeclaratorParamPack(ASTBase):
def is_function_type(self): def is_function_type(self):
return self.next.is_function_type() return self.next.is_function_type()
def describe_signature(self, signode, mode, env): def describe_signature(self, signode, mode, env, parentScope):
_verify_description_mode(mode) _verify_description_mode(mode)
signode += nodes.Text("...") signode += nodes.Text("...")
if self.next.name: if self.next.name:
signode += nodes.Text(' ') signode += nodes.Text(' ')
self.next.describe_signature(signode, mode, env) self.next.describe_signature(signode, mode, env,
parentScope=parentScope)
class ASTDeclaratorParen(ASTBase): class ASTDeclaratorParen(ASTBase):
@ -1348,12 +1358,14 @@ class ASTDeclaratorParen(ASTBase):
def is_function_type(self): def is_function_type(self):
return self.inner.is_function_type() return self.inner.is_function_type()
def describe_signature(self, signode, mode, env): def describe_signature(self, signode, mode, env, parentScope):
_verify_description_mode(mode) _verify_description_mode(mode)
signode += nodes.Text('(') signode += nodes.Text('(')
self.inner.describe_signature(signode, mode, env) self.inner.describe_signature(signode, mode, env,
parentScope=parentScope)
signode += nodes.Text(')') signode += nodes.Text(')')
self.next.describe_signature(signode, "noneIsName", env) self.next.describe_signature(signode, "noneIsName", env,
parentScope=parentScope)
class ASTDecleratorNameParamQual(ASTBase): class ASTDecleratorNameParamQual(ASTBase):
@ -1434,14 +1446,16 @@ class ASTDecleratorNameParamQual(ASTBase):
res.append(text_type(self.paramQual)) res.append(text_type(self.paramQual))
return u''.join(res) return u''.join(res)
def describe_signature(self, signode, mode, env): def describe_signature(self, signode, mode, env, parentScope):
_verify_description_mode(mode) _verify_description_mode(mode)
if self.declId: if self.declId:
self.declId.describe_signature(signode, mode, env) self.declId.describe_signature(signode, mode, env,
parentScope=parentScope)
for op in self.arrayOps: for op in self.arrayOps:
op.describe_signature(signode, mode, env) op.describe_signature(signode, mode, env)
if self.paramQual: if self.paramQual:
self.paramQual.describe_signature(signode, mode, env) self.paramQual.describe_signature(signode, mode, env,
parentScope=parentScope)
class ASTInitializer(ASTBase): class ASTInitializer(ASTBase):
@ -1523,13 +1537,15 @@ class ASTType(ASTBase):
res.append(text_type(self.decl)) res.append(text_type(self.decl))
return u''.join(res) return u''.join(res)
def describe_signature(self, signode, mode, env): def describe_signature(self, signode, mode, env, parentScope):
_verify_description_mode(mode) _verify_description_mode(mode)
self.declSpecs.describe_signature(signode, 'markType', env) self.declSpecs.describe_signature(signode, 'markType', env,
parentScope=parentScope)
if (self.decl.require_space_after_declSpecs() and if (self.decl.require_space_after_declSpecs() and
len(text_type(self.declSpecs)) > 0): len(text_type(self.declSpecs)) > 0):
signode += nodes.Text(' ') signode += nodes.Text(' ')
self.decl.describe_signature(signode, mode, env) self.decl.describe_signature(signode, mode, env,
parentScope=parentScope)
class ASTTypeWithInit(ASTBase): class ASTTypeWithInit(ASTBase):
@ -1561,9 +1577,10 @@ class ASTTypeWithInit(ASTBase):
res.append(text_type(self.init)) res.append(text_type(self.init))
return u''.join(res) return u''.join(res)
def describe_signature(self, signode, mode, env): def describe_signature(self, signode, mode, env, parentScope):
_verify_description_mode(mode) _verify_description_mode(mode)
self.type.describe_signature(signode, mode, env) self.type.describe_signature(signode, mode, env,
parentScope=parentScope)
if self.init: if self.init:
self.init.describe_signature(signode, mode) self.init.describe_signature(signode, mode)
@ -1581,13 +1598,14 @@ class ASTBaseClass(ASTBase):
res.append(text_type(self.name)) res.append(text_type(self.name))
return u''.join(res) return u''.join(res)
def describe_signature(self, signode, mode, env): def describe_signature(self, signode, mode, env, parentScope):
_verify_description_mode(mode) _verify_description_mode(mode)
if self.visibility != 'private': if self.visibility != 'private':
signode += addnodes.desc_annotation( signode += addnodes.desc_annotation(self.visibility,
self.visibility, self.visibility) self.visibility)
signode += nodes.Text(' ') signode += nodes.Text(' ')
self.name.describe_signature(signode, mode, env) self.name.describe_signature(signode, mode, env,
parentScope=parentScope)
class ASTClass(ASTBase): class ASTClass(ASTBase):
@ -1622,17 +1640,19 @@ class ASTClass(ASTBase):
res.append(text_type(b)) res.append(text_type(b))
return u''.join(res) return u''.join(res)
def describe_signature(self, signode, mode, env): def describe_signature(self, signode, mode, env, parentScope):
_verify_description_mode(mode) _verify_description_mode(mode)
if self.visibility != 'public': if self.visibility != 'public':
signode += addnodes.desc_annotation( signode += addnodes.desc_annotation(
self.visibility, self.visibility) self.visibility, self.visibility)
signode += nodes.Text(' ') signode += nodes.Text(' ')
self.name.describe_signature(signode, mode, env) self.name.describe_signature(signode, mode, env,
parentScope=parentScope)
if len(self.bases) > 0: if len(self.bases) > 0:
signode += nodes.Text(' : ') signode += nodes.Text(' : ')
for b in self.bases: for b in self.bases:
b.describe_signature(signode, mode, env) b.describe_signature(signode, mode, env,
parentScope=parentScope)
signode += nodes.Text(', ') signode += nodes.Text(', ')
signode.pop() signode.pop()
@ -1664,17 +1684,19 @@ class ASTEnum(ASTBase):
res.append(text_type(self.underlyingType)) res.append(text_type(self.underlyingType))
return u''.join(res) return u''.join(res)
def describe_signature(self, signode, mode, env): def describe_signature(self, signode, mode, env, parentScope):
_verify_description_mode(mode) _verify_description_mode(mode)
# self.scoped has been done by the CPPEnumObject # self.scoped has been done by the CPPEnumObject
if self.visibility != 'public': if self.visibility != 'public':
signode += addnodes.desc_annotation( signode += addnodes.desc_annotation(
self.visibility, self.visibility) self.visibility, self.visibility)
signode += nodes.Text(' ') signode += nodes.Text(' ')
self.name.describe_signature(signode, mode, env) self.name.describe_signature(signode, mode, env,
parentScope=parentScope)
if self.underlyingType: if self.underlyingType:
signode += nodes.Text(' : ') signode += nodes.Text(' : ')
self.underlyingType.describe_signature(signode, 'noneIsName', env) self.underlyingType.describe_signature(signode, 'noneIsName', env,
parentScope=parentScope)
class ASTEnumerator(ASTBase): class ASTEnumerator(ASTBase):
@ -1695,9 +1717,10 @@ class ASTEnumerator(ASTBase):
res.append(text_type(self.init)) res.append(text_type(self.init))
return u''.join(res) return u''.join(res)
def describe_signature(self, signode, mode, env): def describe_signature(self, signode, mode, env, parentScope):
_verify_description_mode(mode) _verify_description_mode(mode)
self.name.describe_signature(signode, mode, env) self.name.describe_signature(signode, mode, env,
parentScope=parentScope)
if self.init: if self.init:
self.init.describe_signature(signode, 'noneIsName') self.init.describe_signature(signode, 'noneIsName')
@ -2456,7 +2479,7 @@ class CPPObject(ObjectDescription):
def parse_definition(self, parser): def parse_definition(self, parser):
raise NotImplementedError() raise NotImplementedError()
def describe_signature(self, signode, ast): def describe_signature(self, signode, ast, parentScope):
raise NotImplementedError() raise NotImplementedError()
def handle_signature(self, sig, signode): def handle_signature(self, sig, signode):
@ -2484,10 +2507,9 @@ class CPPObject(ObjectDescription):
]) ])
set_lastname(name) set_lastname(name)
raise ValueError raise ValueError
self.describe_signature(signode, ast)
ast.prefixedName = set_lastname(ast.name) ast.prefixedName = set_lastname(ast.name)
assert ast.prefixedName assert ast.prefixedName
self.describe_signature(signode, ast, parentScope=ast.prefixedName)
return ast return ast
@ -2498,9 +2520,10 @@ class CPPTypeObject(CPPObject):
def parse_definition(self, parser): def parse_definition(self, parser):
return parser.parse_type_object() return parser.parse_type_object()
def describe_signature(self, signode, ast): def describe_signature(self, signode, ast, parentScope):
signode += addnodes.desc_annotation('type ', 'type ') signode += addnodes.desc_annotation('type ', 'type ')
ast.describe_signature(signode, 'lastIsName', self.env) ast.describe_signature(signode, 'lastIsName', self.env,
parentScope=parentScope)
class CPPMemberObject(CPPObject): class CPPMemberObject(CPPObject):
@ -2510,8 +2533,9 @@ class CPPMemberObject(CPPObject):
def parse_definition(self, parser): def parse_definition(self, parser):
return parser.parse_member_object() return parser.parse_member_object()
def describe_signature(self, signode, ast): def describe_signature(self, signode, ast, parentScope):
ast.describe_signature(signode, 'lastIsName', self.env) ast.describe_signature(signode, 'lastIsName', self.env,
parentScope=parentScope)
class CPPFunctionObject(CPPObject): class CPPFunctionObject(CPPObject):
@ -2521,8 +2545,9 @@ class CPPFunctionObject(CPPObject):
def parse_definition(self, parser): def parse_definition(self, parser):
return parser.parse_function_object() return parser.parse_function_object()
def describe_signature(self, signode, ast): def describe_signature(self, signode, ast, parentScope):
ast.describe_signature(signode, 'lastIsName', self.env) ast.describe_signature(signode, 'lastIsName', self.env,
parentScope=parentScope)
class CPPClassObject(CPPObject): class CPPClassObject(CPPObject):
@ -2543,9 +2568,10 @@ class CPPClassObject(CPPObject):
def parse_definition(self, parser): def parse_definition(self, parser):
return parser.parse_class_object() return parser.parse_class_object()
def describe_signature(self, signode, ast): def describe_signature(self, signode, ast, parentScope):
signode += addnodes.desc_annotation('class ', 'class ') signode += addnodes.desc_annotation('class ', 'class ')
ast.describe_signature(signode, 'lastIsName', self.env) ast.describe_signature(signode, 'lastIsName', self.env,
parentScope=parentScope)
class CPPEnumObject(CPPObject): class CPPEnumObject(CPPObject):
@ -2576,13 +2602,14 @@ class CPPEnumObject(CPPObject):
assert False assert False
return ast return ast
def describe_signature(self, signode, ast): def describe_signature(self, signode, ast, parentScope):
prefix = 'enum ' prefix = 'enum '
if ast.scoped: if ast.scoped:
prefix += ast.scoped prefix += ast.scoped
prefix += ' ' prefix += ' '
signode += addnodes.desc_annotation(prefix, prefix) signode += addnodes.desc_annotation(prefix, prefix)
ast.describe_signature(signode, 'lastIsName', self.env) ast.describe_signature(signode, 'lastIsName', self.env,
parentScope=parentScope)
class CPPEnumeratorObject(CPPObject): class CPPEnumeratorObject(CPPObject):
@ -2592,9 +2619,10 @@ class CPPEnumeratorObject(CPPObject):
def parse_definition(self, parser): def parse_definition(self, parser):
return parser.parse_enumerator_object() return parser.parse_enumerator_object()
def describe_signature(self, signode, ast): def describe_signature(self, signode, ast, parentScope):
signode += addnodes.desc_annotation('enumerator ', 'enumerator ') signode += addnodes.desc_annotation('enumerator ', 'enumerator ')
ast.describe_signature(signode, 'lastIsName', self.env) ast.describe_signature(signode, 'lastIsName', self.env,
parentScope=parentScope)
class CPPNamespaceObject(Directive): class CPPNamespaceObject(Directive):

View File

@ -574,6 +574,12 @@ class StandardDomain(Domain):
break break
else: else:
continue continue
elif node.traverse(addnodes.toctree):
n = node.traverse(addnodes.toctree)[0]
if n.get('caption'):
sectname = n['caption']
else:
continue
else: else:
# anonymous-only labels # anonymous-only labels
continue continue

View File

@ -487,6 +487,10 @@ def get_figtype(node):
from docutils import nodes from docutils import nodes
if isinstance(node, nodes.figure): if isinstance(node, nodes.figure):
return 'figure' return 'figure'
elif isinstance(node, nodes.image) and isinstance(node.parent, nodes.figure):
# bare image node is not supported because it doesn't have caption and
# no-caption-target isn't a numbered figure.
return 'figure'
elif isinstance(node, nodes.table): elif isinstance(node, nodes.table):
return 'table' return 'table'
elif isinstance(node, nodes.container): elif isinstance(node, nodes.container):

View File

@ -333,7 +333,8 @@ class HTMLTranslator(BaseTranslator):
if isinstance(node.parent, nodes.container) and node.parent.get('literal_block'): if isinstance(node.parent, nodes.container) and node.parent.get('literal_block'):
self.add_permalink_ref(node.parent, _('Permalink to this code')) self.add_permalink_ref(node.parent, _('Permalink to this code'))
elif isinstance(node.parent, nodes.figure): elif isinstance(node.parent, nodes.figure):
self.add_permalink_ref(node.parent, _('Permalink to this image')) self.add_permalink_ref(
node.parent.traverse(nodes.image)[0], _('Permalink to this image'))
elif node.parent.get('toctree'): elif node.parent.get('toctree'):
self.add_permalink_ref(node.parent.parent, _('Permalink to this toctree')) self.add_permalink_ref(node.parent.parent, _('Permalink to this toctree'))

View File

@ -10,6 +10,8 @@ Contents:
.. toctree:: .. toctree::
:maxdepth: 2 :maxdepth: 2
:numbered: :numbered:
:caption: Table of Contents
:name: mastertoc
extapi extapi
images images
@ -54,3 +56,9 @@ This used to crash:
.. toctree:: .. toctree::
:hidden: :hidden:
Test for issue #1700
====================
:ref:`mastertoc`

View File

@ -141,11 +141,17 @@ Adding \n to test unescaping.
* :ref:`admonition-section` * :ref:`admonition-section`
* :ref:`here <some-label>` * :ref:`here <some-label>`
* :ref:`my-figure` * :ref:`my-figure`
* :ref:`my-figure-name`
* :ref:`my-table` * :ref:`my-table`
* :ref:`my-table-name`
* :ref:`my-code-block` * :ref:`my-code-block`
* :ref:`my-code-block-name`
* :numref:`my-figure` * :numref:`my-figure`
* :numref:`my-figure-name`
* :numref:`my-table` * :numref:`my-table`
* :numref:`my-table-name`
* :numref:`my-code-block` * :numref:`my-code-block`
* :numref:`my-code-block-name`
* :doc:`subdir/includes` * :doc:`subdir/includes`
* ``:download:`` is tested in includes.txt * ``:download:`` is tested in includes.txt
* :option:`Python -c option <python -c>` * :option:`Python -c option <python -c>`
@ -172,6 +178,7 @@ Tables
.. _my-table: .. _my-table:
.. table:: my table .. table:: my table
:name: my-table-name
+----+----------------+----+ +----+----------------+----+
| 1 | * Block elems | x | | 1 | * Block elems | x |
@ -199,6 +206,7 @@ Figures
.. _my-figure: .. _my-figure:
.. figure:: img.png .. figure:: img.png
:name: my-figure-name
My caption of the figure My caption of the figure
@ -237,6 +245,7 @@ Code blocks
.. code-block:: ruby .. code-block:: ruby
:linenos: :linenos:
:caption: my ruby code :caption: my ruby code
:name: my-code-block-name
def ruby? def ruby?
false false

View File

@ -256,8 +256,8 @@ def test_numref_with_language_ja(app, status, warning):
print(result) print(result)
print(status.getvalue()) print(status.getvalue())
print(warning.getvalue()) print(warning.getvalue())
assert '\\renewcommand{\\figurename}{Fig. }\n' in result assert '\\renewcommand{\\figurename}{Fig. }' in result
assert '\\renewcommand{\\tablename}{Table }\n' in result assert '\\renewcommand{\\tablename}{Table }' in result
assert '\\floatname{literal-block}{Listing }' in result assert '\\floatname{literal-block}{Listing }' in result
assert '\\hyperref[index:fig1]{Fig. \\ref{index:fig1}}' in result assert '\\hyperref[index:fig1]{Fig. \\ref{index:fig1}}' in result
assert '\\hyperref[baz:fig22]{Figure\\ref{baz:fig22}}' in result assert '\\hyperref[baz:fig22]{Figure\\ref{baz:fig22}}' in result

View File

@ -55,7 +55,7 @@ def test_code_block_caption_html(app, status, warning):
html = (app.outdir / 'caption.html').text(encoding='utf-8') html = (app.outdir / 'caption.html').text(encoding='utf-8')
caption = (u'<div class="code-block-caption">' caption = (u'<div class="code-block-caption">'
u'<span class="caption-text">caption <em>test</em> rb' u'<span class="caption-text">caption <em>test</em> rb'
u'</span><a class="headerlink" href="#id1" ' u'</span><a class="headerlink" href="#caption-test-rb" '
u'title="Permalink to this code">\xb6</a></div>') u'title="Permalink to this code">\xb6</a></div>')
assert caption in html assert caption in html
@ -178,7 +178,7 @@ def test_literalinclude_caption_html(app, status, warning):
html = (app.outdir / 'caption.html').text(encoding='utf-8') html = (app.outdir / 'caption.html').text(encoding='utf-8')
caption = (u'<div class="code-block-caption">' caption = (u'<div class="code-block-caption">'
u'<span class="caption-text">caption <strong>test</strong> py' u'<span class="caption-text">caption <strong>test</strong> py'
u'</span><a class="headerlink" href="#id2" ' u'</span><a class="headerlink" href="#caption-test-py" '
u'title="Permalink to this code">\xb6</a></div>') u'title="Permalink to this code">\xb6</a></div>')
assert caption in html assert caption in html

View File

@ -38,7 +38,7 @@ def check(name, input, idv1output=None, idv2output=None, output=None):
print("Result: ", res) print("Result: ", res)
print("Expected: ", output) print("Expected: ", output)
raise DefinitionError("") raise DefinitionError("")
ast.describe_signature([], 'lastIsName', None) ast.describe_signature([], 'lastIsName', None, parentScope=ast.name)
# Artificially set the prefixedName, otherwise the get_id fails. # Artificially set the prefixedName, otherwise the get_id fails.
# It would usually have been set in handle_signarue. # It would usually have been set in handle_signarue.
ast.prefixedName = ast.name ast.prefixedName = ast.name