Skip to content

Commit 3fbe4ac

Browse files
committed
Implement nocontentsentry flag
1 parent 66da829 commit 3fbe4ac

File tree

8 files changed

+41
-23
lines changed

8 files changed

+41
-23
lines changed

doc/usage/restructuredtext/domains.rst

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,15 @@ Basic Markup
4242
Most domains provide a number of :dfn:`object description directives`, used to
4343
describe specific objects provided by modules. Each directive requires one or
4444
more signatures to provide basic information about what is being described, and
45-
the content should be the description. A domain will typically keep an
46-
internal index of all entities to aid cross-referencing. Typically it will
47-
also add entries in the shown general index.
45+
the content should be the description.
46+
47+
A domain will typically keep an internal index of all entities to aid
48+
cross-referencing.
49+
Typically it will also add entries in the shown general index.
4850
If you want to suppress the addition of an entry in the shown index, you can
4951
give the directive option flag ``:noindexentry:``.
52+
If you want to exclude the object description from the table of contents, you
53+
can give the directive option flag ``:nocontentsentry:``.
5054
If you want to typeset an object description, without even making it available
5155
for cross-referencing, you can give the directive option flag ``:noindex:``
5256
(which implies ``:noindexentry:``).
@@ -57,6 +61,10 @@ options.
5761
The directive option ``noindexentry`` in the Python, C, C++, and Javascript
5862
domains.
5963

64+
.. versionadded:: 5.2.3
65+
The directive option ``:nocontentsentry:`` in the Python, C, C++, Javascript,
66+
and reStructuredText domains.
67+
6068
An example using a Python domain directive::
6169

6270
.. py:function:: spam(eggs)
@@ -523,7 +531,7 @@ For functions with optional parameters that don't have default values
523531
argument support), you can use brackets to specify the optional parts:
524532

525533
.. py:function:: compile(source[, filename[, symbol]])
526-
:noindex:
534+
:nocontentsentry:
527535

528536
It is customary to put the opening bracket before the comma.
529537

@@ -580,7 +588,7 @@ explained by an example::
580588
This will render like this:
581589

582590
.. py:function:: send_message(sender, recipient, message_body, [priority=1])
583-
:noindex:
591+
:nocontentsentry:
584592

585593
Send a message to a recipient
586594

@@ -1166,23 +1174,23 @@ visibility statement (``public``, ``private`` or ``protected``).
11661174
The example are rendered as follows.
11671175
11681176
.. cpp:type:: std::vector<int> MyList
1169-
:noindex:
1177+
:nocontentsentry:
11701178
11711179
A typedef-like declaration of a type.
11721180
11731181
.. cpp:type:: MyContainer::const_iterator
1174-
:noindex:
1182+
:nocontentsentry:
11751183
11761184
Declaration of a type alias with unspecified type.
11771185
11781186
.. cpp:type:: MyType = std::unordered_map<int, std::string>
1179-
:noindex:
1187+
:nocontentsentry:
11801188
11811189
Declaration of a type alias.
11821190
11831191
.. cpp:type:: template<typename T> \
11841192
MyContainer = std::vector<T>
1185-
:noindex:
1193+
:nocontentsentry:
11861194
11871195
.. rst:directive:: .. cpp:enum:: unscoped enum declaration
11881196
.. cpp:enum-struct:: scoped enum declaration
@@ -1277,7 +1285,7 @@ Options
12771285
12781286
Some directives support options:
12791287
1280-
- ``:noindexentry:``, see :ref:`basic-domain-markup`.
1288+
- ``:noindexentry:`` and ``:nocontentsentry:``, see :ref:`basic-domain-markup`.
12811289
- ``:tparam-line-spec:``, for templated declarations.
12821290
If specified, each template parameter will be rendered on a separate line.
12831291
@@ -1878,7 +1886,7 @@ The JavaScript domain (name **js**) provides the following directives:
18781886
This is rendered as:
18791887

18801888
.. js:function:: $.getJSON(href, callback[, errback])
1881-
:noindex:
1889+
:nocontentsentry:
18821890

18831891
:param string href: An URI to the location of the resource.
18841892
:param callback: Gets called with the object.
@@ -1908,7 +1916,7 @@ The JavaScript domain (name **js**) provides the following directives:
19081916
This is rendered as:
19091917

19101918
.. js:class:: MyAnimal(name[, age])
1911-
:noindex:
1919+
:nocontentsentry:
19121920

19131921
:param string name: The name of the animal
19141922
:param number age: an optional age for the animal
@@ -1955,12 +1963,12 @@ The reStructuredText domain (name **rst**) provides the following directives:
19551963
will be rendered as:
19561964

19571965
.. rst:directive:: foo
1958-
:noindex:
1966+
:nocontentsentry:
19591967

19601968
Foo description.
19611969

19621970
.. rst:directive:: .. bar:: baz
1963-
:noindex:
1971+
:nocontentsentry:
19641972

19651973
Bar description.
19661974

@@ -1979,13 +1987,13 @@ The reStructuredText domain (name **rst**) provides the following directives:
19791987
will be rendered as:
19801988

19811989
.. rst:directive:: toctree
1982-
:noindex:
1990+
:nocontentsentry:
19831991

19841992
.. rst:directive:option:: caption: caption of ToC
1985-
:noindex:
1993+
:nocontentsentry:
19861994
19871995
.. rst:directive:option:: glob
1988-
:noindex:
1996+
:nocontentsentry:
19891997
19901998
.. rubric:: options
19911999

@@ -2014,7 +2022,7 @@ The reStructuredText domain (name **rst**) provides the following directives:
20142022
will be rendered as:
20152023

20162024
.. rst:role:: foo
2017-
:noindex:
2025+
:nocontentsentry:
20182026

20192027
Foo description.
20202028

sphinx/directives/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ class ObjectDescription(SphinxDirective, Generic[T]):
5151
final_argument_whitespace = True
5252
option_spec: OptionSpec = {
5353
'noindex': directives.flag,
54+
'noindexentry': directives.flag,
55+
'nocontentsentry': directives.flag,
5456
}
5557

5658
# types of doc fields that this directive handles, see sphinx.util.docfields
@@ -211,6 +213,7 @@ def run(self) -> List[Node]:
211213
node['objtype'] = node['desctype'] = self.objtype
212214
node['noindex'] = noindex = ('noindex' in self.options)
213215
node['noindexentry'] = ('noindexentry' in self.options)
216+
node['nocontentsentry'] = ('nocontentsentry' in self.options)
214217
if self.domain:
215218
node['classes'].append(self.domain)
216219
node['classes'].append(node['objtype'])

sphinx/domains/c.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3142,8 +3142,8 @@ class CObject(ObjectDescription[ASTDeclaration]):
31423142
"""
31433143

31443144
option_spec: OptionSpec = {
3145-
'noindex': directives.flag,
31463145
'noindexentry': directives.flag,
3146+
'nocontentsentry': directives.flag,
31473147
}
31483148

31493149
def _add_enumerator_to_parent(self, ast: ASTDeclaration) -> None:

sphinx/domains/cpp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7186,8 +7186,8 @@ class CPPObject(ObjectDescription[ASTDeclaration]):
71867186
]
71877187

71887188
option_spec: OptionSpec = {
7189-
'noindex': directives.flag,
71907189
'noindexentry': directives.flag,
7190+
'nocontentsentry': directives.flag,
71917191
'tparam-line-spec': directives.flag,
71927192
}
71937193

sphinx/domains/javascript.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class JSObject(ObjectDescription[Tuple[str, str]]):
4040
option_spec: OptionSpec = {
4141
'noindex': directives.flag,
4242
'noindexentry': directives.flag,
43+
'nocontentsentry': directives.flag,
4344
}
4445

4546
def get_display_prefix(self) -> List[Node]:
@@ -284,7 +285,8 @@ class JSModule(SphinxDirective):
284285
optional_arguments = 0
285286
final_argument_whitespace = False
286287
option_spec: OptionSpec = {
287-
'noindex': directives.flag
288+
'noindex': directives.flag,
289+
'nocontentsentry': directives.flag,
288290
}
289291

290292
def run(self) -> List[Node]:

sphinx/domains/python.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ class PyObject(ObjectDescription[Tuple[str, str]]):
427427
option_spec: OptionSpec = {
428428
'noindex': directives.flag,
429429
'noindexentry': directives.flag,
430+
'nocontentsentry': directives.flag,
430431
'module': directives.unchanged,
431432
'canonical': directives.unchanged,
432433
'annotation': directives.unchanged,
@@ -1008,6 +1009,7 @@ class PyModule(SphinxDirective):
10081009
'platform': lambda x: x,
10091010
'synopsis': lambda x: x,
10101011
'noindex': directives.flag,
1012+
'nocontentsentry': directives.flag,
10111013
'deprecated': directives.flag,
10121014
}
10131015

sphinx/domains/rst.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ class ReSTMarkup(ObjectDescription[str]):
2929
Description of generic reST markup.
3030
"""
3131
option_spec: OptionSpec = {
32-
'noindex': directives.flag,
3332
'noindexentry': directives.flag,
33+
'nocontentsentry': directives.flag,
3434
}
3535

3636
def add_target_and_index(self, name: str, sig: str, signode: desc_signature) -> None:

sphinx/environment/collectors/toctree.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,12 @@ def build_toc(
112112
# Skip if no name set
113113
if not sig_node.get('_toc_name', ''):
114114
continue
115+
# Skip if explicitly disabled
116+
if sig_node.parent.get('nocontentsentry'):
117+
continue
115118
# Skip entries with no ID (e.g. with :noindex: set)
116119
ids = sig_node['ids']
117-
if not ids or sig_node.parent.get('noindexentry'):
120+
if not ids:
118121
continue
119122

120123
anchorname = _make_anchor_name(ids, numentries)

0 commit comments

Comments
 (0)